JavaScript で 数値を四捨五入する(Math.round)
Published Feb 12, 2025
⋅
Updated Mar 12, 2025
JavaScript の Math.round()
関数は、与えられた数値を四捨五入した(最も近い整数に丸めた)値を返す。
console.log(Math.round(0.9));
// expected output: 1
console.log(Math.round(5.95), Math.round(5.5), Math.round(5.05));
// expected output: 6 6 5
console.log(Math.round(-5.05), Math.round(-5.5), Math.round(-5.95));
// expected output: -5 -5 -6
参考