You first example is very confused - you try to use a number of uninitialised variables. By changing it to:
my $som_rekening = "2147483648"; my $pad_len_sum = 15; my $padded_som = sprintf("%0${pad_len_sum}s", $som_rekening); print "PADDED SOM: $padded_som - $som_rekening\n";
I believe I've now worked out what the problem is - it prints out:
PADDED SOM: 000002147483647 - 2147483648
It looks like you're running up against the limits of Perl's numeric accuracy. You might find that that Math::BigInt module will allow you to deal with larger numbers.
If, on the other hand, you are formatting this number to display it in some way, why not just treat it as a string like this:
my $som_rekening = "2147483648"; my $pad_len_sum = 15; my $padded_som = sprintf("%0${pad_len_sum}s", $som_rekening); print "PADDED SOM: $padded_som - $som_rekening\n";
This outputs:
--PADDED SOM: 000002147483648 - 2147483648
"The first rule of Perl club is you do not talk about
Perl club."
-- Chip Salzenberg
In reply to Re: perls long number problem
by davorg
in thread perls long number problem
by toadi
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |