PHP money_format() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
String

Definition

In PHP, money_format() used to format a number as a currency string using the locale.

It was deprecated in PHP 7.4 and removed in PHP 8.0, so you should use number_format() or NumberFormatter now.

Syntax

Call money_format() with the values you need. Start with this line.

PHP
$price = number_format(1234.5, 2);
CallWhat it does
money_format("%i", 1234.5)Old code. Removed in PHP 8.0 and now causes a fatal error.
number_format(1234.5, 2)Returns "1,234.50". The simple replacement.
$fmt->formatCurrency(1234.5, "USD")Returns "$1,234.50" using NumberFormatter from the intl extension.

The old function also did not exist on Windows. Plan on using number_format() or NumberFormatter in all new code.

Library declarations
PHP
money_format(string $format, float $number): string

Parameters

ParameterDescription
formatRequired. The old format specification, such as %i or %n.
numberRequired. The number to format.

Return Value

Return ValueDescription
stringThe formatted string. This only applies to PHP 7.4 and older.

PHP Examples

Example 1 — Check If money_format() Exists

On PHP 8 the function is gone. This test shows how to detect it safely.

PHP
<?php
if (function_exists("money_format")) {
    echo "money_format() exists", PHP_EOL;
} else {
    echo "money_format() was removed in PHP 8.0", PHP_EOL;
}

How It Works

  1. Ask PHP. function_exists checks without calling the function.
  2. Avoid a fatal error. Calling a missing function stops the script.
  3. Run on PHP 8. The else branch runs.
  4. Move on. Use one of the replacements in the next examples.

Example 2 — Replace It with number_format()

The simplest fix is to format the number yourself and add the symbol.

PHP
<?php
$amount = 1234.5;

echo '$' . number_format($amount, 2), PHP_EOL;
echo number_format($amount, 2, ",", ".") . " EUR", PHP_EOL;

How It Works

  1. Pick the amount. It is a float.
  2. Use two decimals. number_format rounds to 2 places.
  3. Add your own symbol. Place it before or after the number.
  4. Swap separators. The 3rd and 4th arguments change the style.

Example 3 — Use NumberFormatter for Real Currency

The intl extension has a full currency formatter that follows locale rules.

PHP
<?php
$fmt = new NumberFormatter("en_US", NumberFormatter::CURRENCY);

echo $fmt->formatCurrency(1234.5, "USD"), PHP_EOL;

How It Works

  1. Create the formatter. Pass a locale and the CURRENCY style.
  2. Call formatCurrency. Give it the number and a currency code.
  3. Get a ready string. The symbol and separators are added for you.
  4. Requirement. The intl extension must be enabled.

Frequently Asked Questions

It formatted a number as a currency string using the current locale, with a format similar to printf(). It was available in PHP 4.3 to 7.4.
No. It was deprecated in PHP 7.4 and removed in PHP 8.0. Calling it throws an Error.
Use number_format() for simple needs or the NumberFormatter class from the intl extension for locale-aware currency formatting.
It depended on the C library strfmon(), which is not available on every system such as Windows, and it behaved differently between platforms.
number_format() does not add a symbol. Add it yourself with string concatenation, like "$" . number_format($price, 2).

Next: nl_langinfo()

nl_langinfo() returns language and locale details for a given item, such as day names or t.

nl_langinfo() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful