推荐学习书目
› 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 · 3553 views
    This topic created in 2039 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
    luckyc
    luckyc
    Apr 8, 2021 via iPhone
    2
    type 一下看看类型是什么。你大概就知道了
    crclz
    crclz
    Apr 8, 2021
    3
    IEEE754
    lahmsworld
    lahmsworld
    Apr 8, 2021 via iPhone
    4
    浮点数不精准的原因
    krixaar
    krixaar
    Apr 9, 2021
    5
    之前有一次做稽核的时候需要 Excel 一个单元格减相邻的三个单元格判断是不是 0,然后碰到了类似=0.48-0.26-0.22-0 这样的情况,最后的 if(单元格=0)就很炸裂,然后乖乖的后面先三个求和再减了。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   665 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 118ms · UTC 20:09 · PVG 04:09 · LAX 12:09 · JFK 15:09
    ♥ Do have faith in what you're doing.