php保留两位小数的三种方法
around:
a.代码:
a.代码:
<?php$num1 = round(5,2);$num2 = round(5.123,2);echo $num1.PHP_EOL;echo $num2.PHP_EOL;
b.输出:
55.12
sprintf:
a.代码:
<?php$num1 = sprintf('%.2f',5);$num2 = sprintf('%.2f',5.123);echo $num1.PHP_EOL;echo $num2.PHP_EOL;
b.输出:
5.005.12
number_format(推荐):
a.代码:
<?php$num1 = number_format(5,2);$num2 = number_format(5.123,2);echo $num1.PHP_EOL;echo $num2.PHP_EOL;
b.输出:
5.005.12
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。