新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)Python教程:python中如何使用round函數(shù)
在python3中,ROUND(1.0/2.0)得到的是1,而在python2中,round(1.0/2.0)得到的是0

$ 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)
number,要四舍五入的數(shù),digits是要小數(shù)點(diǎn)后保留的位數(shù)
如果 digits 大于 0,則四舍五入到指定的小數(shù)位。 如果 digits 等于 0,則四舍五入到最接近的整數(shù)。 如果 digits 小于 0,則在小數(shù)點(diǎn)左側(cè)進(jìn)行四舍五入。 如果round函數(shù)只有參數(shù)number,等同于digits 等于 0。
返回的值是四舍五入后的值。python學(xué)習(xí)網(wǎng),大量的免費(fèi)python學(xué)習(xí)視頻,歡迎在線學(xué)習(xí)!
分享題目:創(chuàng)新互聯(lián)Python教程:python中如何使用round函數(shù)
轉(zhuǎn)載來于:http://www.5511xx.com/article/cocddhj.html


咨詢
建站咨詢
