どうも、ちょげ(@chogetarou)です。
数値の1の位を切り捨てる方法を紹介します。
方法

数値の1の位を切り捨てるには、Math.floor()を使います。
まず、Math.floor()を呼び出します。
Math.floor()の引数に、数値を10で割った値を指定します。
そして、Math.floor()の結果を10倍します。
const result = Math.floor(number / 10) * 10;
上記の掛け算は、数値の1の位を切り捨てた数値を返します。
使用例
var num = 152.1;
var num2 = 48.861;
var num3 = 5.25749;
const result = Math.floor(num / 10) * 10;
const result2 = Math.floor(num2 / 10) * 10;
const result3 = Math.floor(num3 / 10) * 10;
console.log(result);
console.log(result2);
console.log(result3);
出力:
150
40
0
コメント