How do I format a number to a dollar amount in PHP

nickf picture nickf · Nov 17, 2008 · Viewed 105.5k times · Source

How do you convert a number to a string showing dollars and cents?

eg:
123.45    => '$123.45'
123.456   => '$123.46'
123       => '$123.00'
.13       => '$0.13'
.1        => '$0.10'
0         => '$0.00'

Answer

Darryl Hein picture Darryl Hein · Nov 17, 2008

If you just want something simple:

'$' . number_format($money, 2);

number_format()