[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Integer conversion error
From: |
Chris Marsh |
Subject: |
Re: Integer conversion error |
Date: |
Mon, 30 Apr 2001 18:20:00 -0700 |
> Why is this happening? A float converted to an int should retain the
> same value, not drop .01 as if it were rounding down. Please pardon my
> ignorance if I'm missing something obvious.
This looks like it is just a floating point precision problem. Remember,
floats do not always store exact values; they store approximations to them.
In your case, if you round to the nearest cent, your program should work:
cents = int ((amount+0.005)*100);
Hope this helps
Chris