Code Comments
Programming Forum and web based access to our favorite programming groups._
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
Post Follow-up to this messageOn 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
Post Follow-up to this messageOn 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
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.