Python Forum

Full Version: Confusing Math
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm trying to understand why python has issues with simple math.
If you try to subtract 0.92 from 1 (1-.92) the answer you get is 0.07999999999999996 rather than 0.08
Anybody know why?
It is because the number cannot be represented exactly in base 2. This page explains the issue. By the way, this is not specific to python. Every system that stores floating numbers according to the ieee-754 standard has the same limitations.
More About Floating Points
If you want to be precise. Then you have to use fractions.Fraction.
from fractions import Fraction
a = Fraction(1)
b = Fraction(92, 100)
print(float(a - b))