How to use number format in PHP

In this article I will explain how the number_format() function can be used in PHP.
  • 2420

number_format() function in PHP

  • The number_format() function is used to format a number with grouped thousands.
  • The number_format() function supports one, two, or four parameters (not three).




  • number numberis required parameter. The number to be formatted. the number will be formatted without decimals and with comma (,),  If no other parameters are set.
  • decimals decimal is optional parameter. count the decimals. the number will be formatted with a dot (.), If this parameter is set.
  • decimalpoint decimalpoint is optional parameter. determine for what string to use for decimal point.
  • separator separator is optional parameter. Only the first character of separator is used.


The following example show to how the number_format() function can be used in PHP.



<h3 style="color: green;">number_format() function example in PHP</h3>



    echo number_format($num).'<br>';

    echo number_format($num, 2).'<br>';

    echo number_format($num, 3).'<br>';

    echo number_format($num, 2, ',', '.');






You may also want to read these related articles here
Ask Your Question 
Got a programming related question? You may want to post your question here


More Articles

© 2020 DotNetHeaven. All rights reserved.