PHP number_format Function

What is number_format Function?

Explanation

This function is used to format a number with grouped thousands.

Syntax:


number_format(number,decimals,decimalpoint,separator)

In the above syntax "number" specifies the number to be formatted, "decimals" specifies the number of decimals, "decimalpoint" specifies the string used for decimal point,"seperator" specifies the string to be used for thousands seperator.

Example :


<?php
echo number_format("2000000");
echo "<br />";
echo number_format("2000000",2);
echo "<br />";
echo number_format("2000000",2,",","*");
?>
Result :

2,000,000
2,000,000.00
2*000*000.00

In the above PHP example the default seperator is "," and one can specify a character like a "*" as thousands seperator like given in the last statement.

PHP Topics


Ask Questions

Ask Question