RE: Perl cant add up with sprintf ?

2004-11-26 Thread ext-Chetak.Sasalu
I have an 11 digit number. I want to add another number to it and format to 11 digits as well. my $amount1 = 14313562897; my $amount2 = 0013625; $amount = sprintf("%011d", $amount1 + $amount2); print $amount."\n"; The answer perl gives me is -01 How can this be ? --- When a nu

Re: Perl cant add up with sprintf ?

2004-11-25 Thread Oliver Schnarchendorf
On Fri, 26 Nov 2004 17:47:25 +1100, David Clarke wrote: > As well, if the large number starts with 0, I get an "Illegal octal > digit '8' at test.pl line 2, at end of line". Sorry, forgot this one. A number can't start with a zero (except if it is in front of a comma). If a number starts with a z

Re: Perl cant add up with sprintf ?

2004-11-25 Thread Oliver Schnarchendorf
On Fri, 26 Nov 2004 17:47:25 +1100, David Clarke wrote: > my $amount1 = 14313562897; > my $amount2 = 0013625; > $amount = sprintf("%011d", $amount1 + $amount2); > print $amount."\n"; > > The answer perl gives me is -01 > How can this be ? > > As well, if the large number starts with 0

Re: Perl cant add up with sprintf ?

2004-11-25 Thread Edward WIJAYA
Hi Dave, my $amount2 = 0013625; As you pointed already. 0 is an octal constant $amount = sprintf("%011d", $amount1 + $amount2); and: printf "%d" casts to a signed int unfortunately the printf interface doesn't give a good way to say "deal with this number, whether perl stored it as si

Perl cant add up with sprintf ?

2004-11-25 Thread David Clarke
I have an 11 digit number. I want to add another number to it and format to 11 digits as well. my $amount1 = 14313562897; my $amount2 = 0013625; $amount = sprintf("%011d", $amount1 + $amount2); print $amount."\n"; The answer perl gives me is -01 How can this be ? As well, if th