Name
number_format
Synopsis
string number_format(floatnumber
[, intprecision
[, stringdecimal_separator
, stringthousands_separator
]])
Creates a string representation of
number
. If
precision
is given, the number is rounded
to that many decimal places; the default is no decimal places,
creating an integer. If decimal_separator
and thousands_separator
are provided, they
are used as the decimal-place character and thousands separator,
respectively. They default to the English locale versions (. and ,).
For example:
$number
=
7123.456
;
$english
=
number_format
(
$number
,
2
);
// 7,123.45
$francais
=
number_format
(
$number
,
2
,
','
,
' '
);
// 7 123,45
$deutsche
=
number_format
(
$number
,
2
,
','
,
'.'
);
// 7.123,45
If rounding occurs, proper rounding is performed, which may not
be what you expect (see round
).
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.