117 of 410 menu

The money_format Function

The money_format function converts a number into a string formatted as a monetary value according to the current locale. It accepts a format string as the first parameter and the number to format as the second. The function is only available on systems that support strfmon (e.g., Linux).

Syntax

money_format(format, number);

Example

Formatting a number into a monetary format for the US locale:

<?php setlocale(LC_MONETARY, 'en_US'); echo money_format('%i', 1234.56); ?>

Code execution result:

'USD 1,234.56'

Example

Formatting with precision and currency symbol specification:

<?php setlocale(LC_MONETARY, 'de_DE'); echo money_format('%.2n', 1234.56); ?>

Code execution result:

'1.234,56 EUR'

Example

Formatting a negative number:

<?php setlocale(LC_MONETARY, 'en_GB'); echo money_format('%i', -1234.56); ?>

Code execution result:

'-£1,234.56'

See Also

  • the number_format function,
    which formats a number with thousands separators
  • the sprintf function,
    which returns a formatted string
byenru