推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
tanny
V2EX  ›  Python

新手请教问题:请问这个小数点后是什么原理?

  •  
  •   tanny · Jun 24, 2014 · 4430 views
    This topic created in 4482 days ago, the information mentioned may be changed or developed.


    今天拿来当计算器时,发现其中一个结果后面出现了000000000001

    以后写程序时需要避免这种问题吗?
    oott123
        1
    oott123  
       Jun 24, 2014 via Android   ❤️ 1
    不用,无视之就可以了。
    这恰恰是精度高的表现。

    当然,也许你需要 "%.2f"
    phyng
        2
    phyng  
       Jun 24, 2014   ❤️ 1
    1、浮点数的精度问题。
    2、这样可以好一点:
    >>> 60+58.21
    118.21000000000001
    >>> print 60+58.21
    118.21
    >>>
    jokester
        3
    jokester  
       Jun 24, 2014   ❤️ 1
    浮点数就那么多bit, 不能保证使用到的所有浮点数都是二进制下的有限小数

    需要判断float A == float B时记得用 abs(A-B)<delta 来做
    kkzxak47
        4
    kkzxak47  
       Jun 25, 2014   ❤️ 1
    其实是一个值得深入的问题
    看看这个: http://justjavac.iteye.com/blog/1725977
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2581 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 38ms · UTC 03:37 · PVG 11:37 · LAX 20:37 · JFK 23:37
    ♥ Do have faith in what you're doing.