使用round($number, 1).这将四舍五入到最接近的小数点.
$number = round(.1666666 * $temp, 1);
Run Code Online (Sandbox Code Playgroud)
如果你想要舍入到最近的一半,你可以这样做:
function round_to_half($num)
{
if($num >= ($half = ($ceil = ceil($num))- 0.5) + 0.25) return $ceil;
else if($num < $half - 0.25) return floor($num);
else return $half;
}
$number = round_to_half(.1666666 * $temp);
Run Code Online (Sandbox Code Playgroud)