我有两个日期,可以像平常一样计算时间差。但是我想用计算出的时间差来计算某些百分比。
full_time = (100/percentage) * timdelta
但是看起来它只能与整数相乘。
我该如何使用 float
作为乘数而不是 int
?
示例:
percentage = 43.27
passed_time = fromtimestamp(fileinfo.st_mtime) - fromtimestamp(fileinfo.st_ctime)
multiplier = 100 / percentage # 2.3110700254217702796394730760342
full_time = multiplier * passed_time # BUG: here comes exception
estimated_time = full_time - passed_time
如果使用 int(multiplier)
— 精度会降低。
full_time = passed_time * 100 / int(percentage)
- Colin O'Coal2 != 2.3131
。比较:571 * 2 = 1142
(19,03(3)分钟);571 * 2.3131 = 1320,7801
(22,0130016(6)分钟)。差异约为3分钟(!) - Крайст