我有两个日期,可以像往常一样计算时间增量。
但我想用得到的时间增量来计算一些百分比:
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)
-精度会受到影响。
您可以转换为总秒数并再次转换:
^{} 可从Python2.7获得;在早期版本中使用
您可以使用^{} :
相关问题 更多 >
编程相关推荐