[solved]Converting a large integer into a string of numbers.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

[solved]Converting a large integer into a string of numbers.

Post by onion2k »

I need to convert a large integer like 5055279512315 into a string. Everything I try ends up with PHP converting it into scientific notation though...

Code: Select all

$number = 5055279512315;
$code = strval($number); //5.05527951232E+012
$code = settype($number, "string"); //5.05527951232E+012
$code = (string) $number; //5.05527951232E+012
$code = "$number"; //5.05527951232E+012
$code = substr($number, 0, 12); //5.05527951236
 
Is there a way just turn it straight from the int into a string of the same numbers?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Converting a large integer into a string of numbers.

Post by Christopher »

Code: Select all

$code = sprintf('%s', $number);
(#10850)
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: Converting a large integer into a string of numbers.

Post by onion2k »

Ah, forgot about that one. Cheers.
Post Reply