Skip to content
Advertisement

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

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

JavaScript

Advertisement

Answer

PHP also has money_format().

Here’s an example:

JavaScript

This function actually has tons of options, go to the documentation I linked to to see them.

Note: money_format is undefined in Windows.


UPDATE: Via the PHP manual: https://www.php.net/manual/en/function.money-format.php

WARNING: This function [money_format] has been DEPRECATED as of PHP 7.4.0. Relying on this function is highly discouraged.

Instead, look into NumberFormatter::formatCurrency.

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement