Is it possible to have PHP format currency values, for example: $200 will output as: $200 (without decimals) but with a number like $200.50 it will correctly output $200.50 instead of $200.5?
Thanks! :)
$num_decimals = (intval($amt) == $amt) ? 0 :2;
print ("$".number_format($amt,$num_decimals);
If you don't mind handling the currency on your own, you can simply use the following on the number, to get the correct output.
This solution will always output trailing zeros (xx.x0 or xx.00 depending on the provided number)
$number = 1234
sprintf("%0.2f",$number);
// 1234.00
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