Pattern to match decimal number and interger

Hi,

i've a code

if (($A && ((!($A =~ /^\d+$/)))))
{
 -- -- not a number
}
else
{
--- its number.
}

which matches for integer value, i need to modify that pattern where it matches decimal number with 2 decimal points and also integer value.
for eg: values 10, 10.00. 0.1, 1 , 3 must print successful . and numbers like
10.0000 0.0001, 01.111 and alphabets 11.ssasd should not accept.

Thanks,
asak

Hi,

Try regexp in this script:

use warnings;
use strict;

while ( <DATA> ) {
    chomp;
    printf "%s\n", $_ if /^\d+(?:\.\d{1,2})?$/;
}

__DATA__
10
10.0000
10.00
0.00001
0.1
1
01.111
3
11.ssasd

Regards,
Birei

1 Like

hi Birei,

Thanks a lot.

Regards,
asak

---------- Post updated at 05:57 AM ---------- Previous update was at 05:56 AM ----------

hi,

Found this regx also

if (($A && ((!($A =~ /^\d+(\.\d{1,2})?$/)))))

which works for 2 decimal numbers and inegers.

Thanks,
Asak