Summary of methods for rounding in PHP
This article mainly introduces the method of rounding the PHP implementation, the example summarizes the PHP implementation rounding three common methods, with a certain reference value, the need for friends can refer to the following
This paper summarizes the method of rounding PHP implementation. Share to everyone for your reference. The specific analysis is as follows:
PHP Implementation rounding three methods, respectively through the Number_format function, round function and sprintf formatted output method to achieve rounding
1.number_format Method for rounding
?
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.round Method for rounding
?
1 2 3 |
$number = 1234.5678; Echo Round ($number, 2); 1234.57 |
3.sprintf formatted input for rounding
?
1 2 3 |
$formatted = sprintf ("%s has ¥%01.2f. ", $name, $money); Echo $formatted; Zhang San has ¥123.10. |
I hope this article is helpful to everyone's PHP programming.
http://www.bkjia.com/PHPjc/964000.html www.bkjia.com true http://www.bkjia.com/PHPjc/964000.html techarticle summary of the method of rounding in PHP this article mainly introduces the method of rounding PHP implementation, the example summarizes the PHP implementation of rounding three common methods, with a certain reference value ...