Php uses the number_format function to extract decimal places for analysis. number_format decimal places

Source: Internet
Author: User

Php uses the number_format function to extract decimal places for analysis. number_format decimal places

This example describes how php uses the number_format function to intercept decimals. We will share this with you for your reference. The details are as follows:

We all know that the number_format () function in php can group numbers by thousands, but it will round the number. Is there a way for it to directly discard the decimal places behind the reserved digits without rounding them? Don't worry, please let me know. If you want to keep two decimal places, you can put your number-0.005

For example:

123456.6588

The result you want is:

123,456.65

You can:

$ Num = 123456.6588; echo number_format ($ num-0.005, 2 ,".",",");

If you only want to keep the integer, you can

$ Num = 123456.6588; number_format ($ num-0.5 );

Solve the problem!

Supplement: The editor recommends a php formatting and formatting typographical tool on this site to help you typeset code in future PHP programming:

Php code online formatting and beautification tools:

Http://tools.jb51.net/code/phpformat

In addition, because php belongs to the C language style, the following tool can also format php code:

C language style/HTML/CSS/json code formatting and beautification tools:
Http://tools.jb51.net/code/ccode_html_css_json

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.