Number problem using PERL?

Licursi

New member
I am reading in a number and I have to verify that is <= 12 digits in length. If the number exceeds 12 digits then I have to set it to a default value.

The problem is that the system internally implies that the number has 4 decimal precision. If the number is entered without 4 decimal precision then there are zeros added to the end of the number.

If a number such as 1,234,567,890.12 is read in, it will pass my test that it is 12 or less digits but once the number gets internally it will be represented as 1,234,567,890.1200 and thus be 14 digits.

Any suggestions how to go about ensuring that the number entered is less than 12 all the time?

I am writing this in PERL if that helps but I think the basic pseudocode would be sufficient.

Thanks in advance!
 
#!/usr/bin/perl.exe
use strict;

my($nbr); my($nbr1);

$nbr = "1,234,567,890,123.1200";
$nbr =~ s/,//g;
$nbr1 = sprintf("%.2f", $nbr);
print $nbr1;
 
#!/usr/bin/perl.exe
use strict;

my($nbr); my($nbr1);

$nbr = "1,234,567,890,123.1200";
$nbr =~ s/,//g;
$nbr1 = sprintf("%.2f", $nbr);
print $nbr1;
 
"number of digits" has NOTHING to do with the internal representation. Like the other answer says, use sprintf to make the number as long as you want...
 
Back
Top