python - Sum of floats: unexpected result -


this question has answer here:

the following output surprised me:

1.1 + 2.2 => 3.3000000000000003 

an unexpected small digit came sum. same not happen other addends, e.g.:

3.0 + 0.3 => 3.3 

i tried both in python 2.7 , in 3.4, result same. reason unexpected result of sum?

mainly because binary doesn't play decimal (2 , 10 coprime) , floats have limited precision.


Comments