[EMAIL PROTECTED] wrote:
>
> 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.

You need the ceil() function from the POSIX module. All other solutions here
will fail if the fractional part of the number is zero (for instance 5.000 will
be upgraded to 6, which I presume isn't wanted).

use strict;
use warnings;

use POSIX;

foreach (qw(0.123 1.23 4.7312 5.000)) {
  print ceil($_), "  ";
}

**OUTPUT**

1  2  5  5


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to