In article <43***************@king-cart.com>, Marshall Dudley
<md*****@king-cart.com> wrote:
The code:
$weight = 5.03;
my $gross = int($weight);
my $frac = $weight - $gross;
print "$frac\n";
Should print the decimal part of .03, but gives this instead:
0.0300000000000002
What am I doing wrong?
You are expecting the number 5.03 to be stored precisely in
floating-point binary format, which it cannot.
See 'perldoc -q numbers'
Use
printf "%.2f\n", $frac;
FYI: this newsgroup is defunct. Try comp.lang.perl.misc in the future.
----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---