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:
When it comes to children, there’s one universal truth: the right toy can spark imagination, build skills, and make memories…
In today’s digital age, where screens and gadgets dominate our children’s lives, there’s something heartwarming about a well-loved plush toy…
In a world dominated by screens and fast-paced routines, it’s easy to forget the simple magic of a toy in…
In the heart of Delhi’s vibrant streets lies a world where imagination meets innovation — the magical universe of toys.…
When was the last time a toy truly amazed you—not just as a product, but as a thoughtful tool for…
In the digital age, the way we experience childhood has changed, but the essence remains the same—imagination, exploration, and joy.…