Definition
The number_format() function formats a number with grouped thousands.
Syntax
number_format(number, decimals, decimalpoint, separator)
Parameters
Parameter | Description |
---|---|
number |
Required. The number to be formatted. If no other parameters are set, the number will be formatted without decimals and with comma (, ) as the thousands separator. |
decimals |
Optional. Specifies how many decimals. If this parameter is set, the number will be formatted with a dot (. ) as decimal point. |
decimalpoint |
Optional. Specifies what string to use for decimal point. |
separator |
Optional. Specifies what string to use for thousands separator. Only the first character of separator is used. For example, "xxx" will give the same output as "x". |
Example
<?php
echo number_format("123456789")."<br>";
echo number_format("123456789",2)."<br>";
echo number_format("123456789",2,",",".");