number_format() function in php
PHP number_fomat() function is used to format a number with grouped thousands. It is an inbuilt function of PHP. The return type of this function is number means it returns a formatted number corresponding to the given number.
- $number is a number that is formatted by this function. It is mandatory.
- $decimal is used to decide the position of the decimal point. It is optional.
- $decimal_point represents a string which used for the decimal point. It is also optional.
- $separater_char represents which character is used to separate thousands. If it is a string then only the first character of string used as a separator. It is also optional but if this parameter is given then all the above parameters are required to be given.
<?php $number=500000; $modified_number=number_format($number); echo "Original number is : $number <br>"; echo "Modified number is : $modified_number"; ?>
<?php $number=730550; $modified_number=number_format($number,2); // rounded with 2 decimal position echo "Original number is : $number <br>"; echo "Modified number is : $modified_number"; ?>
Waiting for your comments