in reply to (tye)Re2: Unwanted implicit conversion to float
in thread Unwanted implicit conversion to float
Perhaps I misunderstood what I meant by that!
You are right in this context of course. The round-off errors here are totally unwanted and should be fixed as early as possible.
So the best solution is to work in cents as merlyn suggests as long as we are performing only additions (the error does not happen) and to use sprintf as early as possible and to work with the rounded value when dealing with more elaborate calculations.
Keeping the value as-is and rounding only the printed one is only valid in a scientific context, where the real number is too long to be printed but further calculation should be based on it and not on the rounded value.
|
|---|