Home > Backend Development > PHP Tutorial > Learn the definition and usage of PHP's number_format() function

Learn the definition and usage of PHP's number_format() function

WBOY
Release: 2016-07-25 09:04:51
Original
1018 people have browsed it
  1. echo number_format("1000000");
  2. echo number_format("1000000",2);
  3. echo number_format("1000000",2,",",".");
  4. ? >
Copy the code

output: 1,000,000 1,000,000.00 1.000.000,00

Interesting number_format number_format(number,decimals,decimalpoint,separator)

has four parameters,

The first and second parameters are required, the third and fourth are optional. However, in actual testing, the third and fourth parameters must exist at the same time, that is, either both are set or neither is set.

The third and fourth parameters are not set:

  1. Number_format(13526, 2); echo 13,526.00;
Copy code

If you add up the processed numbers, you will only get 13! .

The third and fourth parameters are set

  1. Number_format(23125, 2, ‘.’,''); echo 23125.00;
Copy the code

If you perform operations on the processed numbers at this time, it will be executed correctly!

The third parameter of this function indicates what the ‘decimal point’ position is used to represent. It can default to . or can be set to ‘,’ and other symbols. Ps: But I believe no one would do this. The fourth one indicates how to divide the number into every thousandth place. If there are no special requirements and operations are to be performed, it is best to set it to empty.



source:php.cn
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