For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > July 2004 > Rounding a negative number









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Rounding a negative number
Perldiscuss - Perl Newsgroups And Mailing Lists

2004-07-22, 8:56 pm


$item = sprintf("%0.2f", $item);
print $item, "\n";

The above code prints -992.99 if $item = -993, while it prints 993.00, if
$item = 993.

Why is the rounded number off by 0.01 if the number is negative?

Thanks,
SU

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com