zoukankan      html  css  js  c++  java
  • Python_内置函数之round的幺蛾子

                           pycharm运行结果
    1
    ret = round(0.5) 2 print(ret) >>> 0 3 4 ret1 = round(1.5) 5 print(ret1) >>> 2 6 7 ret2 = round(2.5) 8 print(ret2) >>> 2 9 10 ret3 = round(3.5) 11 print(ret3) >>> 4 12 13 ret4 = round(4.5) 14 print(ret4) >>> 4

      上边的代码是否发现幺蛾子了呢? 任性吧!说好的四舍五入呢?

      经总结发现一个规律,当小数点前的一位为奇数时,进1.当小数点前的一位为偶数时,去尾舍去.

      以上结论仅限于X.5

    经研究发现:

      python3中同样存在这样的问题.规律与pycharm中的情况一毛一样.

     经科学研究表名,python2中round还是很正经的,完全按照四舍五入的方式去执行.

    >>> print(round(0.5))
    1.0
    >>> print(round(1.5))
    2.0
    >>> print(round(2.5))
    3.0
    >>> print(round(4.5))
    5.0
    >>> print(round(3.5))
    4.0
    

      

  • 相关阅读:
    jquery.stop()停止动画
    字符串转义
    CSS规范 (命名)- 分类方法
    inline-block 间距
    jquery中offset(),position()
    PHP把数组转换为JSON字符串
    json对象
    C#-静态实例
    C#-readonly与const区别
    SQL-事务隔离级别与锁
  • 原文地址:https://www.cnblogs.com/ZN-225/p/9594544.html
Copyright © 2011-2022 走看看