「JavaScript」Math.floorメソッドで少数部分を切り捨てるサンプル

構文
Math.floor(x)
戻り値 指定された数値以下の最大の整数を表す数値です。

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
console.log(Math.floor(6.95));
console.log(Math.floor(7.05));
console.log(Math.floor(8));
console.log(Math.floor(-9.05));
console.log(Math.floor(6.95)); console.log(Math.floor(7.05)); console.log(Math.floor(8)); console.log(Math.floor(-9.05));
console.log(Math.floor(6.95));

console.log(Math.floor(7.05));

console.log(Math.floor(8));

console.log(Math.floor(-9.05));

実行結果

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
 6
 7
 8
 -10
 6  7  8  -10
 6
 7
 8
 -10

 

JavaScript

Posted by arkgame