Name

money_format

Synopsis

string money_format(string format, float number)

Formats number using the values in format as a monetary value and returns the result. The format string begins with a percent sign (%) and consists of the following elements, in order. Except for the conversion character, the specifiers are all optional.

One or more flags as shown below:

= f

An equals sign followed by a character to be used as the fill character; defaults to the space character.

^

If present, disables the use of grouping characters (for example, 1000 instead of 1,000) as defined by the locale.

+

If present, positive numbers are prefaced with +.

!

If present, the currency symbol is not put in the resulting string.

-

If present, all fields are left-justified and padded to the right with the fill character. By default, fields are right-justified and padded to the left with the fill character.

w

A number indicating the minimum field width. The resulting number is padded to at least this many characters; the default is 0.

#n

A number sign (#) followed by the maximum number of digits to put on the left side of the decimal.

.p

A period (.) followed by the number of digits (p) to put on the right side of the decimal.

i

If specified, the number is formatted according to the locale’s international currency format (for example, USD 1,234.56).

n

If specified, the number is formatted according to the locale’s local currency format (for example, $1234.56).

%

Formats the result as a percentage, inserting a percentage (%) character ...

Get Programming PHP, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.