[EMAIL PROTECTED] schreef:
> 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.
Define "next".
You can use POSIX::ceil(),
but then -1.23 becomes -1 and you might want -2 there?
$ echo -1.23 4.1 5 |perl -MPOSIX -nwle'print
[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
[EMAIL PROTECTED] 写道:
> 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.
$number = int($number) + 1;
also does the same thing.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PR
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.
>
>
> -Original Message-
> From: Anirban Adhikary [mailto:[EMAIL PROTECTED]
> Sent: 06 August 2008 06:51
> To: beginners@perl.org
> Subject: Re: how to round off a decimal to the next whole number
>
> On Wed, Aug 6, 2008 at 11:01 AM, <[EMAIL PROTECTED]> wrote:
&g
On Wed, Aug 6, 2008 at 11:01 AM, <[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.
>
> Th