赞
踩
round()是python自带的一个函数,用于数字的四舍五入。
但是round()的输出结果与Python的版本有关:
在python3中,round(1.0/2.0)=0;在python2中,round(1.0/2.0)=1
- $ python
- Python 2.7.8 (default, Jun 18 2015, 18:54:19)
- [GCC 4.9.1] on linux2
- Type "help", "copyright", "credits" or "license" for more information.
- >>> round(0.5)
- 1.0
-
-
- $ python3
- Python 3.4.3 (default, Oct 14 2015, 20:28:29)
- [GCC 4.8.4] on linux
- Type "help", "copyright", "credits" or "license" for more information.
- >>> round(0.5)
- 0
-
使用方法:round(number,digits)
四舍五入规则:
例子:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。