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

number_format() function in PHP

PHPz
Release: 2023-09-13 06:02:02
forward
1661 people have browsed it

number_format() function in PHP

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

Syntax

number_format(num,decimals,decimal_pt,separator)
Copy after login

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");
?>
Copy after login

Output

The following is the output-

10,000,000
Copy after login

Example

Let’s see another example-

Live Demonstration

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

Output

Here is the output-

4,000
Copy after login

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!

Related labels:
source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template