【发布时间】:2021-02-07 23:21:47
【问题描述】:
我有一个浮点数组合(min_number,max_number),我期待以下汇总:
(-19.12, 34.45) "rounded to" (-19.2, 34.5)
(-0.34, -0.22) "rounded to" (-0.4, -0.3)
(-0.58, -0.87) "rounded to" (-0.6, -0.9)
(-0.24, 5.98) "rounded to" (-0.3, 6.0)
(2.57, 22.38) "rounded to" (2.6, 22.4)
请注意,只需要一位小数。然后:
size = int(input('please input: '))
number = (min_number + max_number) / size
那么“数字”也需要四舍五入,还需要一位小数:
10.233333 "rounded to" 10.3
5.744542267888 "rounded to" 5.8
有什么想法吗?非常感谢,
【问题讨论】:
-
这能回答你的问题吗? How to round away from 0 in Python 3.x?
标签: python-3.x math decimal rounding