freelanceprogrammers.org Forum Index » Perl
Re: simple 2 digit number problem
Joined: 23 Apr 2004
Posts: 2
Re: simple 2 digit number problem
Well i think the script below is almost correct except it wont be
able to check if the number is positive i.e. if $number="-1.21" then
the script will fail. Just put a test condition to check if there is
a negative sign at the start of number.
--- In perl_official@yahoogroups.com, "senarai surat" <senarai@h...>
wrote:
> Try this simple script?
>
> #############
> $number="1.21";
> if( ($number=~/.(d{2}/)&&($1>0))
> { isvalid... }
> #############
>
> mean:
> if $number contain `.` with exactly 2 digits after `.` AND that 2
digits is
> more than 0 (positive)
> then it is valid
>
>
>
>
>
> >
> >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
> >
> >
>
> _________________________________________________________________
> Are you in love? Find a date on MSN Personals
http://match.msn.com.my/
Joined: 23 Apr 2004
Posts: 2
Re: simple 2 digit number problem
Well i think the script below is almost correct except it wont be
able to check if the number is positive i.e. if $number="-1.21" then
the script will fail. Just put a test condition to check if there is
a negative sign at the start of number.
--- In perl_official@yahoogroups.com, "senarai surat" <senarai@h...>
wrote:
> Try this simple script?
>
> #############
> $number="1.21";
> if( ($number=~/.(d{2}/)&&($1>0))
> { isvalid... }
> #############
>
> mean:
> if $number contain `.` with exactly 2 digits after `.` AND that 2
digits is
> more than 0 (positive)
> then it is valid
>
>
>
>
>
> >
> >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
> >
> >
>
> _________________________________________________________________
> Are you in love? Find a date on MSN Personals
http://match.msn.com.my/
All times are GMT
Page 1 of 1
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Freelace Website Designer - Customer web design and software building.
China Wholesale - Electronics Products
Character Studio - Tutorials and Help
China Wholesale - Electronics Products
Character Studio - Tutorials and Help







