有人知道如何在php中格式化数字并将其限制为只显示1位小数吗?
示例:
如何在php中将数字2.10格式化为2.1?
发布于 2011-01-07 11:44:31
使用PHP的number_format
http://php.net/manual/en/function.number-format.php
示例:
$one_decimal_place = number_format(2.10, 1);
如果您需要将其转换回浮点数:
$the_float_value = floatval($one_decimal_place);
此外,对于不同的小数字符和分隔符样式,this文章也是很好的参考。
发布于 2013-03-08 22:31:17
可以使用round函数
echo round(3.4445, 1); // 3.4发布于 2011-01-07 11:44:28
数字格式将为您完成此操作。
$num = 2.10;
number_format($num, 1);PHP: number_format
https://stackoverflow.com/questions/4622328
复制相似问题