开发者

What is float('123.987') in Python?

It's 开发者_高级运维123.98699999999999 !

Why is that?


See Why can't decimal numbers be represented exactly in binary


The Python FAQ and tutorial address this issue pretty well, I think. More generally, both are excellent resources, well worth your time to browse if you have any interest in Python!-)


This has changed in/since Python 3.1.

See also: issue 1580


To your (already deleted) addition: Use the decimal package.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜