Q:

Conversion Issue on Python's int()

When I run this code:  
value = 11.20
dollars = int(value)
print dollars
print 100 * (value - dollars)

Unsurprisingly, I got 11 and 20.0, respectively.
However, when added this line:
print int(100 * (value - dollars))

I got 19.
I searched the web, and got an explanation:

But 0.20 is different. Inside the computer, it's actually a slightly smaller number, so multiplying by 100 gives 19.99999.... When int cuts off the part after the decimal point, 19 is left as the result, instead of the expected 20.

Then I tried:
value_tmp = 0.20
print int(value_tmp * 100)

I got 20, not 19, what's the problem here?

A:

You have a close approximation of 20.0:
>>> value = 11.20
>>> dollars = int(value)
>>> 100 * (value - dollars)
19.99999999999993

That's because you cannot accurately model 2/10th with floating point numbers:
>>> value
11.2
>>> format(value, '.53f')
'11.19999999999999928945726423989981412887573242187500000'

By multiplying the decimal part by 100 you amplified that imprecision. To add to that int() on a float number floors the result.
You could instead round the number to the nearest integer:
>>> round(100 * (value - dollars), 0)
20.0
>>> int(round(100 * (value - dollars), 0))
20

