Home >Backend Development >PHP Tutorial >PHP data displayed separated by thousands separator

PHP data displayed separated by thousands separator

WBOY
WBOYOriginal
2016-07-29 08:59:412543browse

Use the number_format() function in PHP to format numbers by thousands grouping.
number_format(number,decimals,decimalpoint,separator)
number Required. The number to format. If no other parameters are set, numbers are formatted without a decimal point and with commas (,) as delimiters.
decimals optional. Specify the number of decimal places. If this parameter is set, numbers are formatted using a period (.) as the decimal point.
decimalpoint optional. Specifies the string used as the decimal point.
separator optional. Specifies the string used as the thousands separator. Only the first character of the parameter is used. For example, "xyz" only outputs "x".
※Note: If this parameter is set, all other parameters are required.
$number = 1234.56;
//English notation (default)
number_format($number);// 1,235
// French notation
number_format($number,2,',',' ');// 1 234,56 There is a space between the last single quotes
$number = 1234.5678;
// English notation, without thousandth place
number_format($number,2,'.','');// 1234.57
// The most commonly used representation in Chinese, the thousandth place is ',', the floating point separation is '.', and two floating point numbers are reserved
number_format($number,2,'.',',');//1,234.57

The above introduces the display of PHP data separated by thousandth separators, including aspects of the content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
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