假设我在变量$ hours中有数字“13.57916667”。这是将小时和秒组合为小时的计算小时数。
我希望小数位向上舍入。例如,我希望$ hours成为13.6。我似乎无法在任何地方找到任何解决方案,即使在stackoverflow上也是如此。提前谢谢!
答案 0 :(得分:3)
嗯,这个小片段应该这样做:
echo round(13.579, 1);
如果您正在寻找具有精确度的ceil()
:
function ceil_with_precision($value, $precision = 0) {
return ceil($value * pow(10, $precision)) / pow(10, $precision);
}
对于1位小数的固定精度,它将变为:
ceil($value * 10 ) / 10;
答案 1 :(得分:0)
$ result = round($ hours,1);
请参阅round()
答案 2 :(得分:0)
试试这个
$roundednumber= round($number / 10, 0) * 10;
答案 3 :(得分:0)
$hours = (float) "13.57916667";
$hours = ceil($hours * 10) / 10;