## 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 = "," )
2. Usage example:
There is only one parameter<?php $number = 12399.563; //只有一个参数 $number1 = number_format($number); echo "$number1"."<br>"; // 12,400
<?php $number2 =number_format($number,2); echo "$number2"."<br>"; // 12,399.56 ?>
<?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!