Apparently, as @abarnert mentioned in the comment, the GAE env does some stuff on the background, and one of those things is increasing the precision of the float numbers used.
One of the first things you can notice is:
>>> a = 0.88890000000000002
>>> print a
0.8889
Which means that the extra digits are useless.
You can reproduce this situation using the Decimal module:
>>> from decimal import *
>>> Context(prec=17).create_decimal_from_float(0.899).__str__()
'0.89900000000000002'
Interestingly, it looks like GAE is trying to simulate the float precision of ~17 (float
don't have a specific decimal precision, as they're represented as floating point numbers). If it were >17 you would get more decimals, if it were less, the numbers would not be precise enough.
The advantage of using Decimal
is less floating point errors, although it looks like repr()
is having some issues with that.
Check this more extended examples to give more context:
>>> from decimal import *
>>> Context(prec=16).create_decimal_from_float(0.899).__str__()
'0.8990000000000000'
>>> Context(prec=17).create_decimal_from_float(0.899).__str__()
'0.89900000000000002'
>>> Context(prec=18).create_decimal_from_float(0.899).__str__()
'0.899000000000000021'
>>> repr(float(1.0000000000000003)).__str__()
'1.0000000000000002'
>>> Context(prec=17).create_decimal_from_float(1.0000000000000003).__str__()
'1.0000000000000002'
>>> repr(float(1.0000000000000002)).__str__()
'1.0000000000000002'
>>> Context(prec=17).create_decimal_from_float(1.0000000000000002).__str__()
'1.0000000000000002'
>>> repr(float(1.0000000000000001)).__str__()
'1.0'
>>> Context(prec=17).create_decimal_from_float(1.0000000000000001).__str__()
'1'
Finally, the actual number represented by the python float 0.899 is:
>>> from decimal import *
>>> Decimal(float(0.899))
Decimal('0.89900000000000002131628207280300557613372802734375')
So, at the end, the representation provided by repr
in GAE is quite precise.