How PHP uses the Number_format function to intercept decimals

Source: Internet
Author: User
The Number_format () function formats numbers by using thousands of groupings. It returns the formatted number.

Note: The function supports one, two, or four parameters (not three).

This article mainly introduces the method that PHP uses Number_format function to intercept decimals, combined with the example form analyzes the Number_format function to carry on the floating-point number mathematics operation correlation skill, needs the friend can refer to the next

You know that using PHP's Number_format () function, you can group numbers by thousands. But it will round up the numbers, is there any way that it can simply discard the decimals behind the reserved bits without rounding them?

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 do this:

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

If you only want to keep integers, you can

$num =123456.6588;number_format ($num-0.5);
Related Article

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.