For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > April 2005 > Number with More then 15 Digits.









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Number with More then 15 Digits.
Govardhan M. V

2005-04-26, 3:57 pm

_
Hi

$a = 1234567890123456789;
printf ("%0.0f\n", $a);

Out Put is
1234567890123456800

which is wrong can any one let meknow how do we handle
Digits More than 15 digits ..

Regards
Govardhan MV


Offer Kaye

2005-04-26, 3:57 pm

On 26 Apr 2005 11:35:59 -0000, Govardhan M. V wrote:
> =20
> Hi
>=20
> $a =3D 1234567890123456789;
> printf ("%0.0f\n", $a);
>=20
> Out Put is
> 1234567890123456800
>=20
> which is wrong can any one let me know how do we handle
> Digits More than 15 digits ..
>=20


There is no "wrong" here. When trying to store a number larger than
the largest integer possible on your platform, perl converts to float.
Any C app compiled with the same compiler would do the same.
For details of when and which conversions take place, read "perldoc
perlnumber". Anyway, you can use Math::BigInt to handle large
integers.

HTH,
--=20
Offer Kaye
Offer Kaye

2005-04-26, 3:57 pm

On 26 Apr 2005 13:35:27 -0000, Govardhan M. V wrote:
>=20
> Hi,
> Thanks for the help,
> put i tried this=20
> use Math::BigInt;
> $a =3D Math::BigInt->new("12345678901234567890");
> printf("%.0f\n",$a);
> =20
> out put is=20
> 12345678901234567168
> =20
> which is not right so please do let me know how do i go about it .
> My problem is in printing. can you let me know how do i over come this
> issue.
> =20


Hi,
Please don't top post. Please don't use HTML emails. Please reply to the li=
st.

With that out of the way, Depending on your needs, you can use "%s" as
the printf format string, or use simply print:
################ begin code
use strict;
use warnings;
use Math::BigInt;
my $num =3D Math::BigInt->new("12345678901234567890");
print "Orig string: 12345678901234567890\n";
printf "printf output: %s\n",$num;
print "print output: $num\n";
################ end code

HTH,
--=20
Offer Kaye
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com