hlstriker Posted September 26, 2008 Share Posted September 26, 2008 I'm having a problem converting a really big numbers to a string. I have a variable storing the number "76561200929753726". When I try to echo the variable it prints as "7.656119799E+16". How could I convert "7.656119799E+16" back to "76561200929753726" as a string? Quote Link to comment https://forums.phpfreaks.com/topic/125907-solved-convert-big-number-to-string/ Share on other sites More sharing options...
ratcateme Posted September 26, 2008 Share Posted September 26, 2008 try adding ini_set('precision',20); to your script Scott. Quote Link to comment https://forums.phpfreaks.com/topic/125907-solved-convert-big-number-to-string/#findComment-651084 Share on other sites More sharing options...
hlstriker Posted September 26, 2008 Author Share Posted September 26, 2008 EDIT: It works but now I can't do calculations with that variable. Any idea how to fix that? Quote Link to comment https://forums.phpfreaks.com/topic/125907-solved-convert-big-number-to-string/#findComment-651091 Share on other sites More sharing options...
waynew Posted September 26, 2008 Share Posted September 26, 2008 $num = (int) $string; Quote Link to comment https://forums.phpfreaks.com/topic/125907-solved-convert-big-number-to-string/#findComment-651113 Share on other sites More sharing options...
BlueStryke Posted September 26, 2008 Share Posted September 26, 2008 To return the variable correctly, you have to use printf, but for some reason, the rounding is off... $num = "76561200929753726"; printf('%.0f', $num); //Returns 76561200929753728, I have no idea why??? Quote Link to comment https://forums.phpfreaks.com/topic/125907-solved-convert-big-number-to-string/#findComment-651116 Share on other sites More sharing options...
sasa Posted September 26, 2008 Share Posted September 26, 2008 if you have $num="76561200929753726"; in variable $num is STRING and if you try to echo it echo is 76561200929753726 but when you try to do some aritmetic with this variable php convert it in number if you want to calculate with this long number you can setup your aritmetical functions Quote Link to comment https://forums.phpfreaks.com/topic/125907-solved-convert-big-number-to-string/#findComment-651206 Share on other sites More sharing options...
PFMaBiSmAd Posted September 26, 2008 Share Posted September 26, 2008 http://us3.php.net/manual/en/ref.bc.php Quote Link to comment https://forums.phpfreaks.com/topic/125907-solved-convert-big-number-to-string/#findComment-651214 Share on other sites More sharing options...
hlstriker Posted September 26, 2008 Author Share Posted September 26, 2008 The BC Math functions worked. Thanks everyone for your help Quote Link to comment https://forums.phpfreaks.com/topic/125907-solved-convert-big-number-to-string/#findComment-651275 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.