例如,我有1.242533222,我想将其四舍五入。换句话说,我想将浮点数四舍五入到最接近的最大整数。如何在Python 3中做到这一点?
我想将浮点数四舍五入到最接近的最大整数。例如1.232323至2,5.12521369至6,7.12532656至8
您正在寻找一个数字的上限,Python通过该math.ceil()
函数提供了该上限:
$ python3
Python 3.2.5 (default, Jul 30 2013, 20:11:30)
[GCC 4.8.1] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import math
>>> math.ceil(1.232323)
2
>>> math.ceil(5.12521369)
6
>>> math.ceil(7.12532656)
8
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句