Jump to content

[SOLVED] 2 digits to the left of decimal not showing up


jaxdevil

Recommended Posts

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;
?>

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

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;
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.