This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: elementary multiplication by 0.01 error
Type: behavior Stage: resolved
Components: Versions: Python 3.7
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: rhettinger, tonys_0
Priority: normal Keywords:

Created on 2021-02-22 01:37 by tonys_0, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (2)
msg387485 - (view) Author: Tony (tonys_0) Date: 2021-02-22 01:37
on the >>> prompt type:
>>>717161 * 0.01

the same goes for
>>>717161.0 * 0.01

You can easily find more numbers with similar problem:
for i in range(1000000):
    if len(str(i * 0.01)) > 12:
        print(i, i * 0.01)

I am sure, that this problem was found before and circumvented by:
>>>717161 / 100

but this is hardly the way, one wants to rely on the code.

This is the python version I use:
Python 3.7.2 (tags/v3.7.2:9a3ffc0492, Dec 23 2018, 23:09:28) [MSC v.1916 64 bit (AMD64)] on win32
msg387487 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2021-02-22 01:43
Here is an explanation for the behavior you're seeing:

Here is another famous resource on the subject:

For exact decimal arithmetic, consider using the decimal module:
Date User Action Args
2022-04-11 14:59:41adminsetgithub: 87457
2021-02-22 01:43:34rhettingersetstatus: open -> closed

nosy: + rhettinger
messages: + msg387487

resolution: not a bug
stage: resolved
2021-02-22 01:37:01tonys_0create