English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

PHP Basic Tutorial

PHP Advanced Tutorial

PHP & MySQL

PHP Reference Manual

PHP money_format() Function Usage and Examples

    PHP String Function Manual

    The money_format() function is used to format numbers into currency strings.

Syntax

string money_format ( string $format , float $number )

Definition and usage

Definition and usage

Used to format numbers as currency strings.
This function inserts a formatted number at the percentage sign (%) position in the main string.

Note: The money_format() function cannot work on the Windows platform.

 Return value

Returns the formatted character. The characters before and after the format string are returned as is. If the number passed in is not a number, it will return NULL and produce an E_WARNING.

ParameterSerial number
1

Parameters and descriptions

string

The number to be formatted.

Possible format values:

  • Padding and flags:= - f

  • Specify the character (f) used as padding (for example: %=t uses "t" as padding). The default is to use spaces as padding. - ^

  • + Remove the use of grouping characters. - or (+Specify how positive numbers and negative numbers are displayed. If " + " is used, then use the local setting -and+". (Usually a sign is added before negative numbers, and no sign is added before gifts). If "(" is used, negative numbers are included within the parentheses. The default is to use \

  • ! - Stop using the currency symbol in the output string.

  • - If "-". All fields are left-aligned. The default is right-aligned.

Field width:

  • x - Specify the minimum width of the field (x). The default is 0.

  • #x - Specify the maximum number of digits to the left of the decimal point (x). It is used to keep the formatted output aligned in the same column. If the number of digits is greater than x, this specification will be ignored.

  • .x - Specify the maximum number of digits to the right of the decimal point (x). If x is 0, the decimal point and the digits to the right will not be displayed. The default is to use the local setting.

Conversion character:

  • i - The number is formatted as the international currency format.

  • n - The number is formatted as the national currency format.

  • % - Returns % character.

Note:If multiple of the above format values are used, they must be used in the order specified above and cannot be mixed.

Note:This function is affected by the local settings.

2

number

The number to be inserted at the place of the percentage symbol in the format string.

Online Example

Try the following example, de_DE (Germany) international currency format, and with 2 format international currency with decimal places:

<?php
    //with 2 format international currency with decimal places
   $_input = 1000.56;
   setlocale(LC_MONETARY,"de_DE");
   
   echo money_format("%.2n", $_input);
?>
Test and see‹/›

Output Result

1.000,56 EUR

PHP String Function Manual