首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > perl python >

Python3.2的round()函数的实施结果

2013-01-11 
Python3.2的round()函数的执行结果 round(2.5) #没发生进位2 round(2.501) #进位了3 round(2.555

Python3.2的round()函数的执行结果
>>> round(2.5) #没发生进位
2
>>> round(2.501) #进位了
3
>>> round(2.555, 2) #同样末尾是5,进位了
2.56
>>> round(2.555555, 2) #进位了
2.56
>>> round(2.5000001) #进位了
3

round(2.5)结果为2,而不是3,应该如何解释?


[解决办法]
学会看手册, OK?


round(x[, n]) 
Return the floating point value x rounded to n digits after the decimal point. If n is omitted, it defaults to zero. Delegates to x.__round__(n).

For the built-in types supporting round(), values are rounded to the closest multiple of 10 to the power minus n; if two multiples are equally close, rounding is done toward the even choice (so, for example, both round(0.5) and round(-0.5) are 0, and round(1.5) is 2). The return value is an integer if called with one argument, otherwise of the same type as x.

热点排行