I am making a simple order page the user will select an ammount on 1 page then on the next page it runs this
<?php
$bar = $_POST['bar'];
$sum= $bar * 1.59;
echo "Your price". $sum;
?>
the only problem we are having with this is that if they enter a certain ammount say 10 so for example 10 * 1.59 = 15.90 but it only shows 15.9 for any others it will show the ammount fully e.g for 5 it would show £7.95 - Is there something i could change in the code for it to always show the xx.xx figure instead of xx.x
thanks
I think that this is exactly what you're looking for: http://www.php.net/manual/en/function.money-format.php.
<?php
setlocale(LC_MONETARY, 'en_GB');
...
echo "Your price: " . money_format("%.2n", $sum);
?>
<?php
echo sprintf("Your price %.2f", $sum);
?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With