V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
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
oldbird
V2EX  ›  Python

Python 读取 excel 中的小数问题

  •  
  •   oldbird · Apr 8, 2021 · 3081 views
    This topic created in 1847 days ago, the information mentioned may be changed or developed.

    excel 某列都是 4 位小数,使用 xlrd 读取,有的读取正常(即 python 中变量值与 excel 单元格一致),有的如 0.8345 读出来为 0.83499999999,但 print 仍然是 0.8345,不知道为什么会这样,即打印值和变量值不一致

    5 replies    2021-04-09 08:33:24 +08:00
    momo1999
        1
    momo1999  
       Apr 8, 2021   ❤️ 2
    luckyc
        2
    luckyc  
       Apr 8, 2021 via iPhone
    type 一下看看类型是什么。你大概就知道了
    crclz
        3
    crclz  
       Apr 8, 2021
    IEEE754
    lahmsworld
        4
    lahmsworld  
       Apr 8, 2021 via iPhone
    浮点数不精准的原因
    krixaar
        5
    krixaar  
       Apr 9, 2021
    之前有一次做稽核的时候需要 Excel 一个单元格减相邻的三个单元格判断是不是 0,然后碰到了类似=0.48-0.26-0.22-0 这样的情况,最后的 if(单元格=0)就很炸裂,然后乖乖的后面先三个求和再减了。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   939 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 37ms · UTC 20:25 · PVG 04:25 · LAX 13:25 · JFK 16:25
    ♥ Do have faith in what you're doing.