Php processing method with comma-separated thousands of Characters

Source: Internet
Author: User
Php processing method with a comma-separated digit. For more information, see.

Php processing method with a comma-separated digit. For more information, see.

Generally, number_format (); is used to format numbers. By default, the Delimiter is separated by commas (,). For example:
The Code is as follows:
Echo number_format ("10000.01231", 2 );
// Take the second digit after the decimal point. The output result is: 10,000.01. The default value is separated by commas.

If we use the background verification to obtain numbers in this format from the client, it will be a bit difficult.

The old fix usually uses filter_input (INPUT_POST, "price", FILTER_VALIDATE_FLOAT) to verify the price. If it is a comma-carrying kilobytes, it will not be obtained.

Therefore, when you confirm that the input is a number, you must first filter out all the thousands of characters and then verify them.

In fact, few people will input numbers with a kilobytes of characters, unless they are copied or the original output value is submitted again.

When outputting data, we can try to use the number format with a thousand characters as little as possible. The output can be written as follows:
The Code is as follows:
Format_number ("10000.01231", 2 ,".","");
// This output is 10000.01

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.