This article mainly introduces the methods of rounding in PHP. The examples summarize the three common methods of rounding in PHP, which has certain reference value. , friends in need can refer to it
The example in this article summarizes the method of rounding in PHP. Share it with everyone for your reference. The specific analysis is as follows:
Three ways to implement rounding in PHP, using the number_format function, round function and sprintf formatted output method to achieve rounding
1.number_format method implements rounding
?
3 4
5
|
// 1 234,57 $english_format_number = number_format($number, 2, '.', '');
// 1234.57
|
1 2 3 |
$formatted = sprintf ("%s有¥%01.2f。",$name, $money); echo $formatted; //张三有¥123.10。 |
?
$number = 1234.5678; echo round($number ,2); //1234.57 |
1 2 3 | $formatted = sprintf ("%s has ¥%01.2f.",$name, $money); echo $formatted; //Zhang Sanyou¥123.10. |