on Mon, 01 Jul 2002 18:32:27 GMT, Ned Cunningham wrote: > Can anyone tell me how to print the following data so that it rounds > up even though it shouldn't???? > $data = "3.424"; > [...] > I need it to round up even if it is only .001 ?????
use strict; use POSIX qw(ceil); sub roundup { my $number = shift; my $decimals = shift; return undef unless defined($number) && $number > 0 && $decimals >= 0; return sprintf("%.${decimals}f", ceil($number*10**$decimals)/10**$decimals); } print roundup(3.424,2), "\n"; # prints 3.43 print roundup(3.401,2), "\n"; # prints 3.41 print roundup(3.391,2), "\n"; # prints 3.40 -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]