stacie1 Posted March 8, 2008 Share Posted March 8, 2008 Hi all i have a script that get the numbers from a SQL table, rounds them and puts them into an array but the numbers dont come out right and i dont know why php code $wallet = array(); $sql="SELECT balance FROM wallet"; $result = mysql_query($sql) or die('Query failed: ' . mysql_error()); if($result) { while($row = mysql_fetch_assoc($result)) { $balance = round($row["balance"]); $wallet[] = $balance; } } the numbers look like this in the SQL table 3350000000.00 3400000000.00 3440000000.00 3445000000.00 3445000000.00 3449000000.00 3449500000.00 3450000000.00 but come out like this in the array Array ( [0] => 3350000000 [1] => 3.4E+9 [2] => 3.44E+9 [3] => 3.445E+9 [4] => 3.445E+9 [5] => 3.449E+9 [6] => 3449500000 [7] => 3450000000) could someone tell me why this is and how to fix this please? (really new to php by the way) Quote Link to comment https://forums.phpfreaks.com/topic/95114-problem-with-numbers-in-an-array/ Share on other sites More sharing options...
AdamCox9 Posted March 8, 2008 Share Posted March 8, 2008 That is scientific notation. 340 = 3.4E2 3400 = 3.4E3 34000 = 3.4E4 340000 = 3.4E5 ie: it is to the power of 10. Use sprintf to translate it: http://us3.php.net/sprintf Quote Link to comment https://forums.phpfreaks.com/topic/95114-problem-with-numbers-in-an-array/#findComment-487220 Share on other sites More sharing options...
BlueSkyIS Posted March 8, 2008 Share Posted March 8, 2008 or number_format($large_number,0,'.',''); Quote Link to comment https://forums.phpfreaks.com/topic/95114-problem-with-numbers-in-an-array/#findComment-487222 Share on other sites More sharing options...
laffin Posted March 8, 2008 Share Posted March 8, 2008 shud mention it shud be used on the line $wallet[] = number_format($balance); Quote Link to comment https://forums.phpfreaks.com/topic/95114-problem-with-numbers-in-an-array/#findComment-487245 Share on other sites More sharing options...
stacie1 Posted March 8, 2008 Author Share Posted March 8, 2008 thank you ^^ why does it only do that on some of the numbers though? Quote Link to comment https://forums.phpfreaks.com/topic/95114-problem-with-numbers-in-an-array/#findComment-487260 Share on other sites More sharing options...
BlueSkyIS Posted March 8, 2008 Share Posted March 8, 2008 some of your numbers are higher than the precision set (and/or available) on your system. i got the same results here and researched what to do about it. Quote Link to comment https://forums.phpfreaks.com/topic/95114-problem-with-numbers-in-an-array/#findComment-487263 Share on other sites More sharing options...
stacie1 Posted March 8, 2008 Author Share Posted March 8, 2008 ok thank you again Quote Link to comment https://forums.phpfreaks.com/topic/95114-problem-with-numbers-in-an-array/#findComment-487282 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.