舍入小数点后的第二位数字以产生漂亮的数字
Round second digit after decimal to produce nice number
需要将 30.61
舍入到 30.60
,PHP 的任何内置函数都可以做到这一点?
如果我正确理解你想要的输出,你只想舍入第二个小数点,你可以用 1 个小数点舍入,然后使用 numer_format()
来确保你得到正确的小数位数。
$num = 30.61;
echo number_format(round($num, 1), 2);
你可以做到这一点
$num = 3.61;
/*round to nearest decimal place*/
$test_number = round($num,1);
/* ans :3.6
format to 2 decimal place*/
$test_number = sprintf ("%.2f", $test_number);
/* ans : 3.60 */
需要将 30.61
舍入到 30.60
,PHP 的任何内置函数都可以做到这一点?
如果我正确理解你想要的输出,你只想舍入第二个小数点,你可以用 1 个小数点舍入,然后使用 numer_format()
来确保你得到正确的小数位数。
$num = 30.61;
echo number_format(round($num, 1), 2);
你可以做到这一点
$num = 3.61;
/*round to nearest decimal place*/
$test_number = round($num,1);
/* ans :3.6
format to 2 decimal place*/
$test_number = sprintf ("%.2f", $test_number);
/* ans : 3.60 */