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