+ 3
Python Fraction Isuue
I noticed that (n*3) * 0.1, where n = 0.25 to 2 results highly accurate fraction values, like 0.0750000001 or 0.3000000004. However, when n = 3 i.e. 9 * 0.1 gives a proper 0.9! Why this sort of discrepancy?
3 Antworten
+ 8
https://docs.python.org/3/tutorial/floatingpoint.html
+ 3
check this. This is floating point error.
https://www.sololearn.com/discuss/1012768/?ref=app
https://stackoverflow.com/questions/19473770/how-to-avoid-floating-point-errors
+ 1
As a note, if you want to work with real fractions, you can use the fractions module.
from fractions import Fraction
print(Fraction(1,2) + Fraction(1,3))
# 5/6