in reply to Math 101 anyone?

By their very nature, floating point numbers, such as 100.10, can be represented only approximately by finite precision numbers. perl, for instance, uses doubles to represent floating point numbers. On the other hand, integers are represented exactly in perl and only promoted to floating point when a fractional component is encountered.

So to get exact results, do all your calculations in integers, and divide by 100 for display purposes.

-Mark

Replies are listed 'Best First'.
Re^2: Math 101 anyone?
by muntfish (Chaplain) on Oct 12, 2004 at 08:14 UTC
    So to get exact results, do all your calculations in integers, and divide by 100 for display purposes.

    Or, more transparently: use bignum - for example:

    perl -Mbignum -e "print (100.10-100);"

    gives the correct answer 0.1


    s^^unp(;75N=&9I<V@`ack(u,^;s|\(.+\`|"$`$'\"$&\"\)"|ee;/m.+h/&&print$&