JavaScript roundメソッドを使用して四捨五入を計算するサンプル

環境
Google Chrome 109.0.5414.120
Windows 10 Home 64bit

書式
Math.round(値)
roundメソッドを使用して四捨五入を計算します。

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
console.log(Math.round(8.47));
console.log(Math.round(9.77));
console.log(Math.round(-8.401));
console.log(Math.round(-9.501));
console.log(Math.round(8.47)); console.log(Math.round(9.77)); console.log(Math.round(-8.401)); console.log(Math.round(-9.501));
console.log(Math.round(8.47));

console.log(Math.round(9.77));

console.log(Math.round(-8.401));

console.log(Math.round(-9.501));

実行結果
> 8
> 10
> -8
> -10

JavaScript

Posted by arkgame