Sep-25-2019, 02:16 PM
I am a beginner at Python. How does one get Python to be more accurate when doing floating point arithmetic?
For example, in this very simple code:
>
12.040000000000001
12.040000000000001 does not equal 12.04
>>>
For example, in this very simple code:
def AddTwoValues(x, y): return(x + y) firstValue = 8.9 secondValue = 3.14 result = AddTwoValues(firstValue, secondValue) print(result) correctValue = 12.04 if correctValue == result: print(result, " equals ", correctValue) else: print(result, " does not equal ", correctValue)Python returns:
>
12.040000000000001
12.040000000000001 does not equal 12.04
>>>