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

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