PHPnumber_format () function definition and usage

Source: Internet
Author: User
The number_format () function uses a thousand-bit grouping to format numbers.

The number_format () function uses a thousand-bit grouping to format numbers.

The number_format () function uses a thousand-bit grouping to format numbers.

Syntax
Number_format (number, decimals, decimalpoint, separator)
Tips and comments
Note: This function supports one, two, or four parameters (not three ).
Example
The Code is as follows:
Echo number_format ("1000000 ");
Echo number_format ("1000000", 2 );
Echo number_format ("1000000", 2 ,",",".");
?>

Output:

1,000,000
1,000,000.00
1.000.000, 00

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

There are four parameters,

The first and second parameters are required, and the third and fourth parameters are optional. However, in actual tests, the third and fourth parameters must both exist, that is, either set or not set.

The third and fourth parameters are not set:

Number_format (13526, 2); echo 13,526.00;

If you accumulate the processed number, only 13 is returned !.

Set the third and fourth parameters.

Number_format (23125, 2, '.', ''); echo 23125.00;

Then, if you perform an operation on the processed number, it will be executed correctly!

The third parameter of this function indicates the position of the 'decimal point '. It can be set to', 'or other symbols by default. Ps: but I believe no one will do this.
The fourth parameter indicates what is used to separate numbers every thousands of digits. If there are no special requirements, it is best to set it to null if you want to perform computation again.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.