For Programmers: Free Programming Magazines  


Home > Archive > PERL Programming > April 2004 > help: number problem









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 help: number problem
cb

2004-04-18, 11:30 am

I'm sure this is very simple, tried searching google for 2 hrs.

Problem
=======
How do I check if $number is a positive number to 2 decimal places?

ie.

12.12 valid
0 invalid
0.00 invalid
1.0 invalid
12.123 invalid
-1.00 invalid

thanks


John W. Krahn

2004-04-18, 10:34 pm

Xref: kermit alt.perl:27192

cb wrote:
>
> I'm sure this is very simple, tried searching google for 2 hrs.
>
> Problem
> =======
> How do I check if $number is a positive number to 2 decimal places?
>
> ie.
>
> 12.12 valid
> 0 invalid
> 0.00 invalid
> 1.0 invalid
> 12.123 invalid
> -1.00 invalid



if ( 0 + $num && $num eq sprintf '%.2f', abs $num ) {
print "$num\tvalid\n";
}



John
--
use Perl;
program
fulfillment
Sponsored Links







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

Copyright 2008 codecomments.com