Home  >  Article  >  Backend Development  >  number_format() function in PHP

number_format() function in PHP

PHPz
PHPzforward
2023-09-12 23:13:021616browse

number_format() function in PHP

number_format() function is used to format numbers grouped by thousands.

Syntax

number_format(num,decimals,decimal_pt,separator)

Parameters

  • ##num - The number to format.

  • decimals - Specifies the number of decimal places.

  • decimal_pt - String to use for the decimal point.

  • Separator - Specifies the string used for the thousands separator.

Return

number_format() function returns a formatted number.

Example

The following is an example-

Real-time demonstration

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

Output

The following is the output-

10,000,000

Example

Let’s see another example-

Live Demonstration

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

Output

Here is the output-

4,000

The above is the detailed content of number_format() function in PHP. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete