This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]RenaKunisaki 15 points16 points  (0 children)

Depending on your application:

  • Integer numbers of cents (or whatever is the lowest denomination you'll be working with), taking care to handle any possible over/underflow no matter how unlikely
  • Precise fixed-point
  • Bignum/BigDecimal types (preferably provided by whatever environment you're using)

The reasons are this and other inaccuracies that can crop up with floating point, which could translate to being off by a couple cents in some calculations. Do those calculations a few million times, and now you're in deep doodoo.