Python Forum

Full Version: Why is 0.1 * 0.2 arithmetically incorrect?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
On the face of it, this seems an easy sum to do:

>>> 0.2 * 0.1
0.020000000000000004

Python is not good at arithmetic?
See the python FAQ

(which will also suggest that you check out the floating point tutorial.)
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