On Tue, 3 Jan 2006, [EMAIL PROTECTED] wrote:
$result = 10000.00 - 9991.05;
print "\n\$result = $result";
The result that is being printed is "8.95000000000073" instead of "8.95".
Can someone please tell me why perl acts this way. I am beginning to doubt
perl's basic math capabilities.
perl is fine -- it's computers and floating point math you should worry
about :)
One quick fix here is to use printf instead:
printf "\n\%02f = %02f", $result, $result;
The "%02f" is a format specifier. The 0 means to pad the number if it's
not out to 2 places; the 2 is the number of decimal places you want;
and the f is for a floating point number.
dn
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>