I have a value stored in a field as type DecimalField
. When I print it, the value I get is
>>> sr.to_value
Decimal('9.99')
Now when I compare it to a float number
>>> sr.to_value < 9.99
True
Why is this happening ?
Asked
Active
Viewed 45 times
0

Coderaemon
- 3,619
- 6
- 27
- 50
1 Answers
0
Most likely due to floating point inaccuracies, take a look at the docs here for a proper explanation:
https://docs.python.org/3.5/tutorial/floatingpoint.html
Example:
>>> .1 + .1 + .1 == .3
False

Pep_8_Guardiola
- 5,002
- 1
- 24
- 35