Nov-24-2020, 11:18 PM
On the face of it, this seems an easy sum to do:
>>> 0.2 * 0.1
0.020000000000000004
Python is not good at arithmetic?
>>> 0.2 * 0.1
0.020000000000000004
Python is not good at arithmetic?
| Why is 0.1 * 0.2 arithmetically incorrect? |
| Nov-24-2020, 11:18 PM On the face of it, this seems an easy sum to do: >>> 0.2 * 0.1 0.020000000000000004 Python is not good at arithmetic? Nov-24-2020, 11:40 PM Nov-25-2020, 12:01 AM It's the way floating point arithmetic work, Basic Answers. https://0.30000000000000004.com/ There is a Decimal module or other method to overcome this if needed. >>> from decimal import Decimal >>> >>> result = Decimal('0.2') * Decimal('0.1') >>> result Decimal('0.02') >>> print(result) 0.02 |
| |
| Possibly Related Threads… | |||||
| Thread | Author | Replies | Views | Last Post | |
| Code is returning the incorrect values. syntax error | 007sonic | 6 | 4,147 | Jun-19-2023, 03:35 AM Last Post: 007sonic | |
| error 1102 (42000) incorrect database name 's' | Anldra12 | 4 | 3,663 | Jun-08-2022, 09:00 AM Last Post: Anldra12 | |
| openpyxl incorrect delete rows | VladislavM | 6 | 7,608 | Jul-19-2021, 08:54 AM Last Post: VladislavM | |
| Incorrect Type Error | milkycow | 4 | 4,789 | Jun-25-2021, 06:04 AM Last Post: milkycow | |
| user input producing incorrect boolean | al_Czervik | 4 | 4,915 | Mar-05-2020, 09:50 PM Last Post: al_Czervik | |
| Incorrect time format | KoSik | 5 | 4,893 | Aug-15-2019, 05:10 PM Last Post: KoSik | |
| Incorrect code output (File not being created) | Hass | 4 | 4,748 | Jan-01-2019, 04:10 AM Last Post: ichabod801 | |
| Incorrect lambda | vndywarhol | 3 | 4,072 | Aug-13-2018, 02:21 AM Last Post: ichabod801 | |
| mysql.connector - incorrect integer value | Milo | 3 | 15,073 | Aug-14-2017, 06:29 PM Last Post: nilamo | |