Hi,
I'm trying to use a session to store a value for an already calculated total.
The problem I have is that when this session is used in another script, and the value stored within the session is entered into my database, it rounds the number up or down instead of using two decimal places as needed.
For example, the calculated total could be 29.97, but when it is entered into the database, it is entered as 30.
// Calculate the total and sub-totals.
$subtotal = $_SESSION['cart'][$row['isbn']]['quantity'] * $_SESSION['cart'][$row['isbn']]['price'];
$total += $subtotal;
$_SESSION['total'] = number_format ($total, 2);
// Print the row.
echo " <tr>
<td align=\"left\">{$row['title']}</td>
<td align=\"left\">{$row['name']}</td>
<td align=\"right\">£{$_SESSION['cart'][$row['isbn']]['price']}</td>
<td align=\"center\"><input type=\"text\" size=\"3\" name=\"qty[{$row['isbn']}]\" value=\"{$_SESSION['cart'][$row['isbn']]['quantity']}\" /></td>
<td align=\"right\">£" . number_format ($subtotal, 2) . "</td>
</tr>\n";
} // End of the WHILE loop.
mysqli_close($dbc); // Close the database connection.
// Print the footer, close the table, and the form.
echo ' <tr>
<td colspan="4" align="right"><b>Total:<b></td>
<td align="right">£' . number_format ($total, 2) . '</td>
</tr>
</table><div align="center"><input type="submit" name="submit" value="Update My Basket" />
<input type="hidden" name="submitted" value="TRUE" />
</form><br /><br /><a href="submit_order.php"><font size="+2">Submit Order</font></a></div>';
Above is the code used to calculate this total and the creation of the session. I have tried to use a number_format for the session but this doesn't work it the same way that it does in the other two instances it is used within this code.
Any help would be greatly appreciated. Thanks in advance.