Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PHP money_format() Function

PHP money_format() Function

PHP String Reference Manual PHP String Reference Manual

Example

en_US international format:

The code above will output:

The price is USD 1,234.56


Definition and Usage

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

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

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

**Tip:** This function is often used together with setlocale() function.

**Tip:** To view all available language codes, visit ourLanguage Code Reference Manual.


Syntax

money_format(

string,number

)

Parameters Description
string Required. Specifies the string to format and how its variables are formatted.

Possible format values:

Padding and flags:

  • =f - Specifies a character (f) to use as padding (e.g. %=t uses "t" as padding). By default, a space is used as padding.
  • ^ - Remove the use of grouping characters.
  • + or ( - Specifies how to display positive and negative numbers. If "+" is used, the locale's + and - are used (usually a sign before negatives, none before positives). If "(" is used, negatives are enclosed in parentheses. Default is "+".
  • ! - Stop using the currency symbol in the output string.
  • - If "-" is used, all fields are left-aligned. Default is right-aligned.
  • Field width:

    Conversion characters:

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

    Note:This function is affected by the locale setting.

    | | *number* | Required. The number to insert at the % sign position in the formatted string. |

    Technical Details

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

    More examples

    Example 1

    International format with 2 decimals (Germany):

    The code above will output:

    1 234,56 EUR

    Example 2

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

    The code above will output:

    (******1234.57)


    PHP String Reference Manual PHP String Reference Manual