number_format() function in PHP


The number_format() function is used to format a number with grouped thousands.

Syntax

number_format(num,decimals,decimal_pt,separator)

Parameters

  • num − The number to be formatted.

  • decimals − Specifies how many decimals.

  • decimal_pt − The string to be used for decimal point.

  • separator − Specifies the string to be used for thousands separator.

Return

The number_format() function returns the formatted number.

Example

The following is an example −

 Live Demo

<?php
   echo number_format("10000000");
?>

Output

The following is the output −

10,000,000

Example

Let us see another example −

 Live Demo

<?php
   echo number_format("3999.9, 2");
?>

Output

The following is the output −

4,000

Samual Sam
Samual Sam

Learning faster. Every day.

Updated on: 26-Dec-2019

215 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements