PHP number formatting for decimal and thousand places
<?Php
$number=2512589.66785;
echo "Number = $number ";
echo "<br>With formating = ".number_format($number); // 2,512,590
// Three decimal place
echo "<br>With formating = ".number_format($number,3); // 2,512,589.668
// Three decimal place, '.' as decimal separator and # as thousand separator
echo "<br>With formating = ".number_format($number,3,'.','#'); //2#512#589.668
// Two decimal place, ',' as decimal separator and : as thousand separator
echo "<br>With formating = ".number_format($number,2,',',':'); //2:512:589,67
// Two decimal place, '.' as decimal separator and , as thousand separator
echo "<br>With formating = ".number_format($number,2,'.',','); //2,512,589.67
?>
PHP has powerfull math functions. Formatting a number is required while displaying or preparing for some other processing. One common requirement is displaying values after a division with fractions. One way is to round off the number or we can format the number with specifying whether to display the digits with decimal or without decimal or number of digits to display after the decimal. We can place comma ( ,) after a group of thousands. We can use other symbols in place of comma (,) for thousands and we also can replace (.) dot with symbol of our choice to be used as decimal. Using PHP number_format function we can do all these formatting. Here are some examples for number formatting.
← Math FunctionsRounding off value →pow() to get exponential value → ← Subscribe to our YouTube Channel here
This article is written by plus2net.com team.
https://www.plus2net.com
plus2net.com
✖
We use cookies to improve your browsing experience. . Learn more