php processing of Numbers with comma thousands

  • 2020-05-12 02:19:33
  • OfStack

Usually use number_format (); To format Numbers. By default thousands are separated by commas. For example:
 
echo number_format("10000.01231", 2); 
// After the decimal point 2 Bit, the output result is: 10,000.01  The thousands are separated by commas by default.  

It would be a bit of a hassle if we were backstage to verify the Numbers we get from the client in this format.

The old repairman usually USES filter_input(INPUT_POST,"price",FILTER_VALIDATE_FLOAT) to verify the price. If the value is thousands with comma, it will not be obtained.

So you have to filter out all the thousands before you verify that the input is a number.

Very few people enter a number with a thousand, unless they copy it or resubmit the original output.

In the output, we can use the number format with thousands as little as possible. The output can be written like this:
 
format_number("10000.01231",2,".",""); 
// So this is the output 10000.01 

Related articles: