w3resource

PHP: number_format() function

Description

The number_format() function is used to format a number (Floating number) with grouped thousands.

Version:

(PHP 4 and above)

Syntax:

number_format(number, decimals, dec_point, thousands_sep) 

Parameter:

Name Description Required /
Optional
Type
number The input number. Required Float
decimals Refer to the number of decimal points. Optional Integer
dec_point Refers the separator of decimal points. Optional String
thousands_sep Refers the thousands separator. Optional String

Note: The function accepts one, two, or four parameters (not three).

Return value:

A formatted version of the number.

Value Type: String

Pictorial Presentation

php-string-number_format()

Example:

<?php
$number=100000;
echo number_format($number).'<br>';
echo number_format($number, 2).'<br>';
echo number_format($number, 3).'<br>';
echo number_format($number, 2, ',', '.');
?>

Output:

100,000
100,000.00
100,000.000
100.000,00 

View the example in the browser

See also

PHP Function Reference

Previous: nl2br
Next: ord



Inviting useful, relevant, well-written and unique guest posts