Home  >  Article  >  Backend Development  >  Implementation code of php number_format() function to format numbers by thousands grouping_PHP Tutorial

Implementation code of php number_format() function to format numbers by thousands grouping_PHP Tutorial

WBOY
WBOYOriginal
2016-07-21 15:00:35916browse

Definition and Usage
The number_format() function formats a number by grouping by thousands.

Syntax
number_format(number,decimals,decimalpoint,separator)

Parameter Description
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 are optional. Specify the number of decimals. If this parameter is set, numbers are formatted using a period (.) as the decimal point.

decimalpoint is optional. Specifies the string used as the decimal point.

separator Optional. Specifies the string used as 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.

Tips and Notes
Note: This function supports one, two or four arguments (not three).

Example:

Copy code The code is as follows:

echo number_format("1000000");
echo number_format("1000000",2);
echo number_format("1000000",2,",",".");
?>

Output:
Copy code The code is as follows:

1,000,000
1,000,000.00
1.000 .000,00

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/328074.htmlTechArticleDefinition and usage The number_format() function formats numbers by grouping thousands. Syntax number_format(number,decimals,decimalpoint,separator) Parameter Description number Required. To format...
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