in reply to perls long number problem
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: perls long number problem
by toadi (Chaplain) on Dec 10, 2001 at 16:29 UTC | |
by gbarr (Monk) on Dec 10, 2001 at 21:24 UTC |