PHP number format Function | How to format number in php
 PHP
PHP number_format():- PHP number format function gives you a simple way to format numbers for displaying to the user. it is an inbuilt function that is used used to formate a number with grouped thousands. you can separate thousands with commas or other separators, choose the number of decimal places and choose the decimal point character to display (or display no decimals).
The PHP number format returns the formatted number on success otherwise it offers E_WARNING on failure when displaying a number in web pages, it’s nice to format the number in an easy-to-read way.
Parameter Values
| Parameter | Description | 
|---|---|
| $number | This parameter is required. that specify the number to be formatted. If no alternative or other parameters are set, then the number goes to be formatted without the decimals & with a comma (,) as the thousands separator. | 
| $decimals | It is an optional parameter, Specifies how many decimals. If this parameter is set, then the number will be formatted with a dot (.) as a decimal point. | 
| $decimalpoint | Optional, used to specify the string to use for the mathematical notation or decimal point. | 
| $separator | A nonmandatory parameter used to specify what string to use for the thousands separator. the first character of a separator is used. If this parameter is given, then all different or other parameters are required. as an example, “aaa” can offer identical output as “a” | 
Return Value: In success condition, It returns Formatted Number otherwise it gives E_WARNING in failure.
PHP Number Formate:- Basic number formatting
The basic range typeat|data formatting|information|info} form number_format() accepts numbers to formate, and returns a string containing the formatted range, rounded to the closest integer, with commas between every cluster of thousands:
| 1 2 3 4 5 | <?php $number = 1234567.89; // Displays "1,234,568" echo number_format( $number ); ?> | 
PHP number_format()function performs that it returns a string containing separator characters, therefore, we can’t use the output of PHP number format as a numeric value with different functions or maths operators.
Therefore, you do all of your calculations on the original numeric value, and also convert the value
PHP Number Formate:- Using different separators
By default, number_format() uses a comma for the thousands apparatus and a dot for the mathematical
notation. therefore, to use completely different separators, pass the new mathematical notation or decimal
point separator as the third argument, and also the new thousands separator as the fourth argument.
The given below the following example shows a number using the French convention — a space for
the thousands separator and a comma for the decimal point.
		
| 1 2 3 | $number = 123456.784321; // Displays "123 456,78" echo number_format( $number, 2, ',', ' ' ); | 
| 1 2 3 | $number = 123456.784321; // Displays "123456.78" echo number_format( $number, 2, '.', '' ); | 
PHP Number Format Function:- Understand More Example:
| 1 2 3 4 5 | <?php echo number_format("9999999")."<br>"; echo number_format("9999999",2)."<br>"; echo number_format("9999999",2,",","."); ?> | 
| 1 2 3 | 9,999,999 9,999,999.00 9.999.999,00 | 
| 1 2 3 4 5 6 7 | <?php $number=479454251; echo number_format($number).'<br>'; echo number_format($number, 2).'<br>'; echo number_format($number, 3).'<br>'; echo number_format($number, 2, ',', '.'); ?> | 
| 1 2 3 4 | 479,454,251 479,454,251.00 479,454,251.000 479.454.251,00 | 
| 1 2 3 4 5 6 7 | <?php $number = 2999.9; $formated_num = number_format($number)."<br>"; echo $formated_num; $formated_num = number_format($number, 2); echo $formated_num; ?> | 
| 1 2 | 3,000 2,999.90 | 
