Re: Stange problem with sprintf or trace display
- Posted by mattlewis (admin) Mar 13, 2012
- 1113 views
A floating point/rounding problem with a 2 digit atom? Its nowhere near the 31 bit limit!
It can probably get pretty close. Try, for instance, to precisely express 1/3 as a decimal. The radices are different, but the problem is the same.
Strange indeed. Anyway -
If the data input from my user is characters in the format nnnn.cc ,multiple instances.
I have to seperate the cents from the dollars and convert to numeric to add this up.
Can you suggest how to achieve this and avoid the rounding problem?
The simplest is probably to convert to your smallest unit. In this case, track everything in terms of cents. Then you can convert / format that however you need. Alternatively, you could track dollars and cents separately, and manage the borrowing / carrying manually. Some systems use binary coded decimal (BCD). That's probably not a practical approach for euphoria code.
Matt