Search code examples
phpformattingcurrency

PHP Currency formatting trailing zeros


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! :)


Solution

  • $num_decimals = (intval($amt) == $amt) ? 0 :2;
    print ("$".number_format($amt,$num_decimals);