关于python3中round()函数的四舍五入问题
来源:互联网 发布:淘宝千牛店铺名怎么改 编辑:程序博客网 时间:2024/09/21 08:57
round(float [,n])函数用于返回浮点数四舍五入后的值,小数点后保留n位(默认为0)
例如
>>round(3.5248,2)
>>3.52
但是有一个坑就是当保留n位时,第n+1位为数字5,此时它并不会进一位,而是舍弃掉。
例如
>>round(3.585,2)
>>3.58
这并不是BUG,在python手册中这样说到:
The behavior of round() for floats can be surprising: for example, round(2.675, 2) gives 2.67 instead of the expected 2.68. This is not a bug: it’s a resultof the fact that most decimal fractions can’t be represented exactly as a float. See Floating Point Arithmetic: Issues and Limitations for more information.
简单来说,有些浮点数在计算机中并不能像整数那样被准确表达,它可能是近似值。因此就会出现这种问题,解决方法为decimal模块 0 0
- 关于python3中round()函数的四舍五入问题
- 解决access中round函数不能正确四舍五入的问题 (备忘)
- Math.Round函数四舍五入的问题
- Oracle中Round函数(四舍五入)的使用
- 关于 java 中负数四舍五入的问题——Math.round()
- SQL的四舍五入ROUND函数
- SQL的四舍五入ROUND函数
- Math.round()的四舍五入问题
- java中关于小数的四舍五入问题
- Access数据库中round方法四舍五入问题
- oracle round()函数 ----四舍五入函数
- Math.Round 之关于 不同的四舍五入
- Math.Round 之关于 不同的四舍五入
- 关于python3.x的除法、向上向下取整及四舍五入的问题
- MySQL 之 ROUND 函数四舍五入的陷阱
- Math.Round 四舍五入函数
- PHP 四舍五入函数 round()
- mysql 四舍五入round函数
- 【Java基础知识】IO流 详解
- 并查集(模板&典型例题整理)
- UML类图中箭头和线条的含义和用法
- hdu 5938 Four Operations(复杂的模拟题)
- 最小生成树
- 关于python3中round()函数的四舍五入问题
- matlab 中 卷积运算conv2
- 顺序表的实现以及功能;
- 汽车之家-数据挖掘面试
- static成员
- java基础--3.面向对象-4.继承
- 第一天
- Ecshop模板开发(二十六):搜索功能实现
- hdu2089不要62 (数位dp入门题)