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
    

      

  • 相关阅读:
    Codeforces Round #226 (Div. 2)
    内存管理
    C/C++ 函数
    Codeforces Round #225 (Div. 2)
    常用链表操作总结
    Codeforces Round #224 (Div. 2)
    Codeforces Round #223 (Div. 2)
    Codeforces Round #222 (Div. 2)
    -树-专题
    Codeforces Round #221 (Div. 2)
  • 原文地址:https://www.cnblogs.com/ZN-225/p/9594544.html
Copyright © 2011-2022 走看看