There are three methods of rounding in php, which are implemented through the number_format function, the round function and the sprintf formatted output method. 1. The number_format method implements rounding
-
- $number = 1234.5678;
- $nombre_format_francais = number_format($number, 2, ',', ' ');
- // 1 234,57
- $english_format_number = number_format($number, 2, '.', ' ');
- // 1234.57
-
-
Copy code
2 .round method implements rounding
-
- $number = 1234.5678;
- echo round($number ,2);
- //1234.57
-
-
-
Copy code
3.sprintf formatted input implements rounding
-
- $formatted = sprintf ("%s has ¥%01.2f.",$name, $money);
- echo $formatted;
- //Zhang San has ¥123.10.
Copy code
|
Three types, rounded, php