V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
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
bulabean
V2EX  ›  Python

来提个 Python 问题,以前一直没发现,相加的问题

  •  
  •   bulabean · 2017-07-25 11:32:34 +08:00 · 1730 次点击
    这是一个创建于 2475 天前的主题,其中的信息可能已经有所发展或是发生改变。
    >>> 99.95+0.01+0.03+0.01
    Out: 100.00000000000001
    

    add

    有清楚原因的吗?来聊下

    4 条回复    2017-07-25 11:44:31 +08:00
    Duluku
        1
    Duluku  
       2017-07-25 11:35:09 +08:00
    matrixback
        2
    matrixback  
       2017-07-25 11:37:51 +08:00
    浮点数的运算,涉及到底层,每个语言都有个问题吧。
    ipwx
        3
    ipwx  
       2017-07-25 11:42:11 +08:00
    ![不损失精度的运算]( )

    你看,不损失精度的运算,也是很容易构造出来的。关键是你要明白,浮点数到底是什么……
    lixiangzaizheli
        4
    lixiangzaizheli  
       2017-07-25 11:44:31 +08:00
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   971 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 18:42 · PVG 02:42 · LAX 11:42 · JFK 14:42
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.