English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

PHP Basic Tutorial

PHP Advanced Tutorial

PHP & MySQL

PHP Reference Manual

PHP number_format() Function Usage and Example

   PHP String String Functions Manual

    The number_format() function is used to format a number with a thousand separator.

Syntax

number_format(number,decimals,decimalpoint,separator)

Definition and Usage

The function formats numbers by grouping them in thousands.
Note: This function supports one, two, or four parameters (not three).

Return Value

It returns the formatted number.

Parameter

Serial NumberParameters and Description
1

number

Number to be formatted

2

decimals

Number of decimal places to retain

3

decimalpoint

Specify the character to display as the decimal point.

4

separator

Specify the character to display as the thousand separator.

Online Example

Try the following example, number_format() function formats numbers:

<?php
   //number_format() function formats numbers
   $input = 100.9;
   $formattedinput = number_format($input)."<br>";
   echo $formattedinput;
   
   $formattedinput = number_format($input, 2);
   echo $formattedinput;
?>
Test and See‹/›

Output Result

101
100.90

PHP String String Functions Manual