PHP has two decimal places, and php has two decimal places.

Source: Internet
Author: User

PHP has two decimal places, and php has two decimal places.

Recently, I am making statistics on this part. There are many data sources related to numbers,

Three functions are used to retain the last N digits after decimal places. Next, we will briefly introduce the three functions:

1. number_format

Echo number_format ("5000000 "). "<br>"; echo number_format ("5000000", 2 ). "<br>"; echo number_format ("5000000", 2 ,",",". ");

This function is mainly used to format data in sub-groups.

Output result

5,000,000
5,000,000.00
5.000.000,00

2. sprintf

$ Num = 123; $ data = sprintf ("%. 2f", $ num); echo $ data;

The result is:

123.00

3. round

$ Num1 = 123.1267 $ data1 = round ($ num1, 2); $ num2 = 123 $ data2 = round ($ num2, 2 ); echo $ data1. "<br>" echo $ data2

The result is:

123.13

123

If the number of decimal points is less than two, it will not be automatically filled.

 

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.