## In the process of daily use of numbers, there are always some special scenarios where numbers need to be displayed in a specific form. This article mainly talks about how to use number_format () function to display numbers with thousands separators.
1.number_format () syntax
number_format( float $number , int $decimals = 0 , string $dec_point = "." , string $thousands_sep = "," )
- $number: the number to be formatted
- $decimals: The number of decimal places to be retained
- $dec_point: Specify the character displayed for the decimal point
- $thousands_sep: Specify the thousands separator Displayed characters
- If only the first parameter is provided, the decimal part of the number will be removed, and it will be separated by English "," by default.
- If two parameters are provided, number will retain the number of digits after the decimal point to the value of $decimals
- If four parameters are provided, number will retain the decimal part of $decimals length, the decimal point is replaced by $dec_point, and the thousands separator is replaced by $thousands_sep.
2. Usage example:
There is only one parameter<?php $number = 12399.563; //只有一个参数 $number1 = number_format($number); echo "$number1"."<br>"; // 12,400There are two parameters
<?php $number2 =number_format($number,2); echo "$number2"."<br>"; // 12,399.56 ?>There are four parameters
<?php $number = 12348.56789; $number3 = number_format($number, 2, ',', ' '); echo "$number3"."<br>"; // 12 348,57 ?>
Recommended: 《2021 PHP interview questions summary (collection)》《php video tutorial 》
The above is the detailed content of How to format a number with thousands separator in PHP. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Zend Studio 13.0.1
Powerful PHP integrated development environment

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Notepad++7.3.1
Easy-to-use and free code editor

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft
