float equality

Jouko Koski joukokoskispam101 at netti.fi
Mon Feb 21 03:47:37 PST 2011


"Walter Bright" <newshound2 at digitalmars.com> wrote:

> A reasonable way to do financial work is to use longs to represent 
> pennies. After all, you don't have fractional cents in your accounts.

I tend to favor using floating point, doing calculations in pennies, and 
explicitly rounding result to nearest full penny. This is almost the same as 
using longs except that division does not always truncate numbers. 
Fractional pennies are often useful in intermediate results.

If there is some more appropriate type to use, I might be easily convinced 
otherwise. However, I don't think using some indefinite precision number 
type is a fits-for-all solution either, since...

> I.e. you have to know what you're doing :-)

Touche!

-- 
Jouko



More information about the Digitalmars-d mailing list