I have a small difficulty with the php math object.
Whenever I echo a total number it will display okay with 2 decimals, except when the number has .00 it will not.
So 20.00 – 10.00 will display 10 while 20.00 – 9.99 will display 10.01
I would like to always show 2 decimals.
As I search the internet I cannot find the way to add it to my code. I think it should be done with a ‘number_format($total_sub,2)’ , but how?
See example code that parses the end number:
<?php
$less_subtotal= '10.00';
$order_subtotal= '20.00';
$total_sub = abs($order_subtotal - $less_subtotal);
number_format($total_sub, 2);// output is still witouth 2 decimals...
echo $total_sub;
?>
— EDIT —
As I described the posted I knew the problem…. EPIC..
echo number_format($total_sub, 2);
Should be okay now I guess?
1 Answer