本文共 702 字,大约阅读时间需要 2 分钟。
python3 的 round 函数感觉很别扭,其运算结果与习惯不相符。特记录下来:
'''python 3的 round 函数 是“四舍六入五成双”的https://www.zhihu.com/question/20128906'''print('python 3的 round 函数:四舍六入五成双')print('\nround(-3.5) = ', round(-3.5))print('\nround(-2.5) = ', round(-2.5))print('round(-1.5) = ', round(-1.5))print('\nround(-0.5) = ', round(-0.5))print('round(0.5) = ', round(0.5))print('\nround(1.5) = ', round(1.5))print('round(2.5) = ', round(2.5))print('\nround(3.5) = ', round(3.5))print('round(4.5) = ', round(4.5))print('\nround(5.5) = ', round(5.5))print('round(6.5) = ', round(6.5))print('\nround(6.5000000000000001) = ', round(6.5000000000000001)) # 小数点后16位print('round(6.500000000000001) = ', round(6.500000000000001)) # 小数点后15位
转载地址:http://wetyo.baihongyu.com/