Hello guys,
could anyone explain this please ?
# Tests
convert(11.20)
I want to get dollars and cent separately from 11.20. I know, there are probably better ways, but I want to understand, why the int() does not work as I expect.
Why I get from 20.0 the value 19 ? From 20.0 I expect 20
Thank you.
could anyone explain this please ?
def convert(val):
dollars = int(val)
#it returns 11 Ok
cents = 100*(val - dollars)
#it prints 20.0 Ok
#to get whole number of cents, I take only int part of the number
cents_1 = int(cents)
print "cents_1",cents_1 #Why I get from 20.0 the value 19 ? From 20.0 I expect 20. # Tests
convert(11.20)
I want to get dollars and cent separately from 11.20. I know, there are probably better ways, but I want to understand, why the int() does not work as I expect.
Why I get from 20.0 the value 19 ? From 20.0 I expect 20
Thank you.
