a.代码:
<?php
$num1 = round(5,2);
$num2 = round(5.123,2);
echo $num1.PHP_EOL;
echo $num2.PHP_EOL;
b.输出:
5
5.12
a.代码:
<?php
$num1 = sprintf(‘%.2f‘,5);
$num2 = sprintf(‘%.2f‘,5.123);
echo $num1.PHP_EOL;
echo $num2.PHP_EOL;
b.输出:
5.00
5.12
a.代码:
<?php
$num1 = number_format(5,2);
$num2 = number_format(5.123,2);
echo $num1.PHP_EOL;
echo $num2.PHP_EOL;
b.输出:
5.00
5.12
原文地址:http://blog.51cto.com/12173069/2116499
时间: 2024-10-11 04:22:52