number_format() function helps in formating a number (Floating number) with grouped thousands.
[table caption=”” width=”100%” colwidth=”15%|15%|15%|55%” colalign=”left|lef|lef|left”]
Name, Required /Optional, Value Type, Description
number, Required, Float , It is the input number.
decimals, Optional, Integer , It specifies the number for the decimal point.
decimal_point, Optional, String , It specifies the separator for decimal point.
thousands_sep, Optional, String , It specifies the separator for thousands.
[/table]
It returns the formatted number.
[table caption=”” width=”100%” colwidth=”20%|80%” colalign=”left|left”]
Version, Description
PHP 7.2.0, number_format() has been changed not to return -0. However in earlier version -0 could be returned for cases like where number would be -0.05.
PHP 5.4.0 , It supports multiple bytes in dec_point and thousands_sep now. Only the first byte of each separator was used in older versions..
[/table]
<?php $number=999999; echo number_format($number).'<br>'; echo number_format($number, 2).'<br>'; echo number_format($number, 3).'<br>'; echo number_format($number, 2, ',', '.'); ?>
Output of above code in the browser is as below:
<?php $number=999999.99; echo number_format($number).'<br>'; //One parameter will round the number. echo number_format($number, 2).'<br>'; echo number_format($number, 3).'<br>'; echo number_format($number, 2, ',', '.').'<br>'; echo number_format($number, 2, ',', 'x').'<br>'; ?>
Output of above code in the browser is as below:
App usage is growing steadily without showing any signs of slowing down. Hence, it is no surprise that mobile applications…
As the world has grown more digital, businesses have adapted themselves. An effectual adaptation includes online advertising. Offline advertising styles…
Step into a world where apps dance to the user's tune. Picture Instagram, a photo-sharing sensation that swept the globe.…
COVID-19 has led to a digitalization of lifestyle. As patients are taking their mental and physical health more seriously, healthcare…
Introduction WordPress, an immensely popular content management system (CMS), powers over 40% of the internet. What makes WordPress even more…
For moving companies trying to capture their market share amidst stiff competition, a tip or two about what they can…