Your skill will accomplishwhat the force of many cannot PerlMonks

### Re: floating point validation

by govindkailas (Acolyte)
 on Aug 30, 2010 at 12:06 UTC ( #857999=note: print w/replies, xml ) Need Help??

in reply to floating point validation

here is the corrected one :) thanks to all ..
```\$val=101.24;
validate(3,2,\$val);
sub validate{

\$v1=\$_[0];
\$v2=\$_[1];
\$v3=\$_[2];

print "Values are \$v1 \t \$v2 \t \$v3  \n";

if(\$v3=~m/^\d{\$v1}\.\d{\$v2}\$/ ){

print "its a good one\n";}

else {print "Not Good!!";}
}

[download]```

Replies are listed 'Best First'.
Re^2: floating point validation
by Khen1950fx (Canon) on Aug 30, 2010 at 12:20 UTC
I tidied the script for you:).
```#!/usr/bin/perl

use strict;
use warnings;

my \$val = 101.24;
validate( 3, 2, \$val );

sub validate {
my \$v1 = \$_[0];
my \$v2 = \$_[1];
my \$v3 = \$_[2];
print "Values are \$v1 \t \$v2 \t \$v3 \n";

if ( \$v3 =~ m/^\d{\$v1}\.\d{\$v2}\$/ ) {
print "its a good one\n";
}
else {
print "Not Good!!";
}
}
[download]```

I tidied the tidied.

```my \$val = 101.24;
print match_decimal_format( 3, 2, \$val ) ? "Valid!\n" : "Invalid...\n"
+;

sub match_decimal_format {
my ( \$leading, \$trailing, \$number ) = @_;
return \$number =~ m/^ [0-9]{\$leading} \. [0-9]{\$trailing} \$/x;
}
[download]```

Log In?
 Username: Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://857999]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2018-01-16 09:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
How did you see in the new year?

Results (176 votes). Check out past polls.

Notices?