number_format() FunctionFormats a number by thousands grouping. It returns a formatted number.
Note: This function supports one, two or four parameters (not three).
This article mainly introduces the method of intercepting decimals in PHP using number_formatfunction, and analyzes the related skills of number_format function for floating-point mathematical operations in the form of examples. It needs Friends, please refer to
Everyone knows that you can use the number_format() function of php to group numbers by thousands. However, it will round the numbers. Is there any way to directly discard and retain them? What about decimal places after digits without rounding?
If you want to keep two decimal places, you can put your number -0.005
For example:
123456.6588
you want The result to be obtained 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);
The above is the detailed content of How to use number_format function to intercept decimals in PHP. For more information, please follow other related articles on the PHP Chinese website!