Easy Tutorial
❮ Func Libxml Clear Errors Func Mysqli Get Server Version ❯

PHP number_format() Function

PHP String Reference Manual

Example

Formatting a number:


Definition and Usage

The number_format() function formats a number with grouped thousands.

Note: This function supports one, two, or four parameters (not three).


Syntax

Parameter Description
number Required. The number to be formatted. If no other parameters are set, the number will be formatted without decimals and with a comma (,) as the thousands separator.
decimals Optional. Specifies how many decimal points. If this parameter is set, the number will be formatted with a dot (.) as the decimal point.
decimalpoint Optional. Specifies the character string to be used as the decimal point.
separator Optional. Specifies the character string to be used as the thousands separator. Only the first character of this parameter is used. For example, "xxx" will output "x". <br> <br> Note: If this parameter is set, all other parameters are required.

Technical Details

Return Value: Returns the formatted number.
PHP Version: 4+
--- ---
Changelog: Since PHP 5.4, this function supports multibyte characters in the decimalpoint and separator parameters. In previous versions, values used only the first byte of each separator.
--- ---

More Examples

Example 1

You want to return a price: one parameter will round the number (formatted without decimal places), two parameters will give you the desired result:


❮ Func Libxml Clear Errors Func Mysqli Get Server Version ❯