0
預期函數簽名的先前多個:PHP圓整到5小數
function roundToPreviousMultipleWithDecimal(float $number, int $x = 5): float;
- 8.4 => 8.0
- 8.6 => 8.5
- 8.9 => 8.5
- 9.0 => 9.0
預期函數簽名的先前多個:PHP圓整到5小數
function roundToPreviousMultipleWithDecimal(float $number, int $x = 5): float;
一個簡單的解決方案,地板的雙數和除以二... 2美分;)
<?php
function roundToPreviousMultipleWithDecimal(float $number){
return $specificRound = floor($number * 2)/2;
}
$a = 8.4;
$b = 8.6;
$c = 8.9;
$d = 9.0;
echo roundToPreviousMultipleWithDecimal($a) ."<br />";
echo roundToPreviousMultipleWithDecimal($b) ."<br />";
echo roundToPreviousMultipleWithDecimal($c) ."<br />";
echo roundToPreviousMultipleWithDecimal($d) ."<br />";
你已經試過了什麼? –
8.5,9.0,8.0這些都不是5的倍數?我懷疑你的意思是舍入到最接近的0.5 – Luke
是的我的壞,0.5。 – Syl