Easy Tutorial
❮ Func Math Ceil Filter Validate Float ❯

PHP money_format() Function

PHP String Reference Manual

Example

en_US international format:

The above code will output:


Definition and Usage

The money_format() function returns a string formatted as a currency string.

This function inserts a formatted number at the percentage (%) position in the main string.

Note: The money_format() function does not work on Windows platforms.

Tip: This function is often used in conjunction with the setlocale() function.

Tip: For a list of all available language codes, visit our Language Code Reference Manual.


Syntax

Parameter Description
string Required. Specifies the string to be formatted and how to format the variables in it. Possible format values: Padding and flags: =f - Specifies the character (f) to be used as padding (e.g., %=t uses "t" as padding). Default is space padding.<br> ^ - Removes the use of grouping characters.<br> + or ( - Specifies how to display positive and negative numbers. If "+" is used, the local settings for + and - are used (usually a sign before negative numbers and no sign before positive numbers). If "(" is used, negative numbers are enclosed in parentheses. Default is "+".<br> ! - Stops the use of the currency symbol in the output string.<br> - If "-" is used, all fields are left-aligned. Default is right-aligned. Field width: x - Specifies the minimum width of the field (x). Default is 0.<br> #x - Specifies the maximum number of digits to the left of the decimal point (x). Used to keep formatted output aligned in the same column. If the number of digits is greater than x, this specification is ignored.<br> .x - Specifies the maximum number of digits to the right of the decimal point (x). If x is 0, the decimal point and its right digits will not be displayed. Default uses local settings. Conversion characters: i - The number is formatted as an international currency format.<br> n - The number is formatted as a national currency format.<br> % - Returns the % character. Note: If multiple format values are used, they must be used in the order specified above, not shuffled. Note: This function is affected by local settings.
number Required. The number to be inserted at the % symbol position in the formatted string.

Technical Details

Return Value: Returns the formatted string. Characters before and after the formatting string will remain unchanged. Non-numeric values return NULL and produce an E_WARNING.
PHP Version: 4.3.0+
--- ---

More Examples

Example 1

International format with 2 decimal places (Germany):

The above code will output:

Example 2

Negative numbers, US international format with () indicating negative numbers, right precision of 2, "*" as the padding character:

The above code will output:


PHP String Reference Manual

❮ Func Math Ceil Filter Validate Float ❯