One general approach is to maintain and operate on amounts internally as fixed-point integer quantities; e.g., as the number of cents, or possibly mills (tenths of a cent). While the numeric representation used (at least by Perl) is still double-precision floating point, the goal is to never produce a non-zero fractional result. Addition, subtraction and multiplication on integers always yield integer results. Operations that can produce fractional results (e.g., division) must sooner or later (and sooner is usually better) be reconciled into the fixed point representation that has been selected.
Or maybe check out something like integer or Math::FixedPrecision.
In reply to Re^3: perl subtraction
by AnomalousMonk
in thread perl subtraction
by jagdish.eashwar
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |