Re: Stange problem with sprintf or trace display

new topic     » goto parent     » topic index » view thread      » older message » newer message
AJ_Oxley said...

Thanks Matt,
The problem is that I am trying to save the data as characters, so will need to use value() and sprintf() quite a bit when fetching / displaying / accepting input.
In essence you are suggesting that a user may not enter numeric data as chars that contain a period, because of the rounding errors?
Possible bypass is to have seperate list controls designated for dollars and cents; the user would have to tab accross to the cents.
That won't make me popular!

If rounding errors are a problem, then you can't simply convert a fractional number into an atom. In general, monetary rounding errors are considered problematic.

I think the correct approach is to allow your users to do whatever they're doing, but to handle the data carefully inside your program so that you don't get any rounding errors. This should be completely transparent to a user. It makes things more difficult on you, of course, but there's really no way around this.

Databases tend to store things in different formats for this purpose. I know that in Java, a common way to implement money is to use the BigDecimal class, which makes arithmetic more difficult than "normal" numeric types, but has the bonus of avoiding floating point rounding errors.

I was somewhat surprised that a quick search in the archive didn't turn up any libraries that deal with money. I'm sure someone around here must have some code lying around.

Matt

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu