On Wed, 2008-08-06 at 13:31 +0800, [EMAIL PROTECTED] wrote:
> Hi,
> How do I round off a decimal to the next nearest whole digit ,
> example
> 0.123 = 1,
> 1.23 = 2,
> 4.7312 = 5, etc etc.....
>
> Right now I can only do the above by extracting the first digit using splice
> , then add one.
>
> Thanks
>
>
#!/usr/bin/perl
use POSIX;
my @nbrs = (
0.123,
1.23,
4.7312,
);
for my $n ( @nbrs ){
print "number: $n\n";
printf "\tceil: %d\n", ceil( $n );
printf "\tfloor: %d\n", floor( $n );
printf "\tround: %.0f\n", $n;
}
__END__
--
Just my 0.00000002 million dollars worth,
Shawn
"Where there's duct tape, there's hope."
"Perl is the duct tape of the Internet."
Hassan Schroeder, Sun's first webmaster
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/