PHP with comma thousand digit processing method _php Tips

Source: Internet
Author: User
usually with Number_format (); To format numbers, the default thousand are separated by commas, such as:
Copy Code code as follows:

Echo Number_format ("10000.01231", 2);
2 digits after the decimal point, the output result is: 10,000.1000 digits are separated by commas.

It would be a bit of a hassle if we were backstage verifying the numbers in this format that were obtained from the client.

Old practitioners commonly used filter_input (Input_post, "price", filter_validate_float) to verify prices, if it is a comma with the thousand character will not be obtained.

So when you confirm that the input is a number, you first filter out all the thousand characters and then verify.

In fact, very few people will enter numbers with the thousand characters, unless they are copied or the original output value is resubmitted.

In the output we can use as little as possible with the number of thousand characters format, the output can be written:
Copy Code code as follows:

Format_number ("10000.01231", 2, ".", "");
That's 10000.01 of the output.

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.