割り算の余りの処理

floor 余りを切り捨てる
ceil 余りを切り上げる
round 四捨五入
$x = 10;
$y = 3;
print floor($x / $y);
print ceil($x / $y);
print round($x / $y);
:実行結果:::

343

round は四捨五入する際の桁数も指定できます

print round($x / $y, 3);
:実行結果:::

3.333

コメント

タイトルとURLをコピーしました