Python浮点数误差与解决方法&保留指定小数位数& 向上取整向下取整

参考:

Python浮点数误差与解决方法:

https://blog.csdn.net/zhouxufeng1996/article/details/94999514?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.nonecase&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.nonecase

 

 

总结:

解决精度问题

方法一:Decimal(str(2.3))

方法二:getcontext

方法三:round四舍五入----------------------推荐用round!!!

注意:python中round函数的一个小坑——奇进偶弃:https://blog.csdn.net/xiaotao_1/article/details/81869350?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-3.control&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-3.control

保留小数位数:

https://blog.csdn.net/liuweiyuxiang/article/details/100574386

向上取整向下取整:

https://www.cnblogs.com/xifengxixia/p/10918117.html

原文地址:https://www.cnblogs.com/erchun/p/13025991.html