Summary of php implementation rounding. Summary of php implementation rounding methods this article mainly introduces php implementation rounding methods, examples summarizes three common methods for php implementation rounding, has a certain reference value php implementation rounding methods summary
This article mainly introduces how to implement rounding in php. The example summarizes three common methods for implementing rounding in php, which has some reference value. For more information, see
This example summarizes the php rounding method. Share it with you for your reference. The specific analysis is as follows:
Php provides three rounding methods: number_format, round, and sprintf.
1. implement rounding of number_format
?
1 2 3 4 5 |
$ Number = 1234.5678; $ Nombre_format_francais = number_format ($ number, 2 ,',',''); // 1 234,57 $ English_format_number = number_format ($ number, 2 ,'.',''); // 1234.57 |
2. implement rounding of the round method
?
1 2 3 |
$ Number = 1234.5678; Echo round ($ number, 2 ); // 1234.57 |
3. sprintf format input implementation rounding
?
1 2 3 |
$ Formatted = sprintf ("% s has ¥ % 01.2f. ", $ Name, $ money ); Echo $ formatted; // Picture 3 has 123.10 RMB. |
I hope this article will help you with php programming.
This article describes how to implement rounding in php. The example summarizes three common methods for implementing rounding in php, which has some reference value...