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 about php implementation, see the examples in this article. 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
$ 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
$ Number = 1234.5678; echo round ($ number, 2); // 1234.57
3. sprintf format input implementation rounding
$ Formatted = sprintf ("% s has ¥ % 01.2f. ", $ Name, $ money); echo $ formatted; // Picture 3 has $123.10.
I hope this article will help you with php programming.