This function accepts either one, two, or four parameters (not three):
If only one parameter is given,numberwill be formatted without decimals, but with a comma (",") between every group of thousands.
If two parameters are given,numberwill be formatted withdecimalsdecimals with a dot (".") in front, and a comma (",") between every group of thousands.
If all four parameters are given,numberwill be formatted withdecimalsdecimals,dec_pointinstead of a dot (".") before the decimals andthousands_sepinstead of a comma (",") between every group of thousands.
Parameters
number
The number being formatted.
decimals
Sets the number of decimal points.
dec_point
Sets the separator for the decimal point.
thousands_sep
Sets the thousands separator.
Return Values
A formatted version ofnumber.
Changelog
VersionDescription
7.2.0
number_format()was changed to not being able to return-0, previously-0could be returned for cases like wherenumberwould be-0.01.
5.4.0
This function now supports multiple bytes indec_pointandthousands_sep. Only the first byte of each separator was used in older versions.