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
oldbird
V2EX  ›  Python

Python 读取 excel 中的小数问题

  •  
  •   oldbird · 2021-04-08 11:17:33 +08:00 · 2066 次点击
    这是一个创建于 1086 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

    5 条回复    2021-04-09 08:33:24 +08:00
    shuax
        1
    shuax  
       2021-04-08 11:24:14 +08:00   ❤️ 2
    l4ever
        2
    l4ever  
       2021-04-08 11:35:49 +08:00 via iPhone
    type 一下看看类型是什么。你大概就知道了
    crclz
        3
    crclz  
       2021-04-08 11:54:29 +08:00
    IEEE754
    lahmsworld
        4
    lahmsworld  
       2021-04-08 14:50:35 +08:00 via iPhone
    浮点数不精准的原因
    krixaar
        5
    krixaar  
       2021-04-09 08:33:24 +08:00
    之前有一次做稽核的时候需要 Excel 一个单元格减相邻的三个单元格判断是不是 0,然后碰到了类似=0.48-0.26-0.22-0 这样的情况,最后的 if(单元格=0)就很炸裂,然后乖乖的后面先三个求和再减了。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2832 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 14:40 · PVG 22:40 · LAX 07:40 · JFK 10:40
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.