jaxdevil Posted November 2, 2007 Share Posted November 2, 2007 Ok, I have my script one step from being done, in one of the scripts it is pulling up the data in a loop, adding up the values, and displaying them, but the sum (the part where it adds it up) is not displaying the cents... the actual row does in the loop, but when it adds all the amount fields from the rows from the loop that part only displays the dollar amount if the cents part are both zeros. So if it is $0.19 that displays correctly (I am not using the dollar symbol on the output though) but if it is $10.00 it just displays the number 10, no decimal, no dots afterwards. Here is the code I am using, PLEASE help... <?php $sql = "SELECT * FROM checkout WHERE bidnum=$bidder AND paid='no'"; $query = mysql_query($sql); $sum = array(); while($row = mysql_fetch_array($query)) { $sum[] = $row['amt']; $di = $row['id']; echo "Lot Number " .$row['lotnum']. ": $" .$row['amt']. "<br>"; } $sum = array_sum($sum); echo "<input type=\"hidden\" name=\"bidder_number\" value=\"$bidder\">"; echo "<input type=\"hidden\" name=\"idx\" value=\"$di\">"; echo "<input type=\"hidden\" name=\"amount\" value=\"$sum\">Total Due: " .$sum; ?> Quote Link to comment https://forums.phpfreaks.com/topic/75754-solved-2-digits-to-the-left-of-decimal-not-showing-up/ Share on other sites More sharing options...
rajivgonsalves Posted November 2, 2007 Share Posted November 2, 2007 use number_format number_format($sum, 2); more information on http://php.net/number_format Quote Link to comment https://forums.phpfreaks.com/topic/75754-solved-2-digits-to-the-left-of-decimal-not-showing-up/#findComment-383381 Share on other sites More sharing options...
jaxdevil Posted November 2, 2007 Author Share Posted November 2, 2007 Thanks again Raj! I am lost on where to insert that at. I literally am on hour 28 and I can literally barely think. If you get a free chance can you show me where/how to insert that? I appreciate all the help you have been through this project! SK Quote Link to comment https://forums.phpfreaks.com/topic/75754-solved-2-digits-to-the-left-of-decimal-not-showing-up/#findComment-383385 Share on other sites More sharing options...
rajivgonsalves Posted November 2, 2007 Share Posted November 2, 2007 here you go, this should work tell me if you have any problems <?php $sql = "SELECT * FROM checkout WHERE bidnum=$bidder AND paid='no'"; $query = mysql_query($sql); $sum = array(); while($row = mysql_fetch_array($query)) { $sum[] = $row['amt']; $di = $row['id']; echo "Lot Number " .$row['lotnum']. ": $" .$row['amt']. "<br>"; } $sum = number_format(array_sum($sum),2); echo "<input type=\"hidden\" name=\"bidder_number\" value=\"$bidder\">"; echo "<input type=\"hidden\" name=\"idx\" value=\"$di\">"; echo "<input type=\"hidden\" name=\"amount\" value=\"$sum\">Total Due: " .$sum; ?> Quote Link to comment https://forums.phpfreaks.com/topic/75754-solved-2-digits-to-the-left-of-decimal-not-showing-up/#findComment-383387 Share on other sites More sharing options...
jaxdevil Posted November 2, 2007 Author Share Posted November 2, 2007 YOU ARE THE MAN!! That did it! I can finally sleep! Thanks a million, you are a life saver! :D :D :D :D SK Quote Link to comment https://forums.phpfreaks.com/topic/75754-solved-2-digits-to-the-left-of-decimal-not-showing-up/#findComment-383388 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.