round【小数点以下四捨五入】メソッド
ceil【小数点以下切り上げ】メソッド
floor【小数点以下切り下げ】メソッド
abs【絶対値】メソッド
Math.round【小数点以下四捨五入:round off】メソッド
メモ
- 小数点以下を四捨五入
- 負の場合も小数部が .5 の場合、切り上げ
- 関連:
構文
Math.round( x )- x:数値
- 小数点以下を四捨五入した整数値
x (参考値) 戻り値 NaN NaN +0 +0 -0 -0 +∞ +∞ -∞ -∞ 0 < x < 0.5 +0 -0.5 ≦ x < 0 -0
例
console.log(Math.round(1.5)); // 出力:2
console.log(Math.round(1.4)); // 出力:1
console.log(Math.round(-1.5)); // 出力:-1
console.log(Math.round(-1.5000001)); // 出力:-2
console.log(Math.round(-1.6)); // 出力:-2
console.log(Math.round(NaN)); // 出力:NaN
console.log(Math.round(+0)); // 出力:0
console.log(Math.round(-0)); // 出力:-0
console.log(Math.round(+Infinity)); // 出力:Infinity
console.log(Math.round(-Infinity)); // 出力:-Infinity
console.log(Math.round(0.4)); // 出力:0
console.log(Math.round(-0.5)); // 出力:-0
Math.ceil【小数点以下切り上げ:ceiling】メソッド
メモ
- 小数点以下を切り上げ
- 関連:
構文
Math.ceil( x )- x:数値
- 小数点以下を切り上げた整数値
x (参考値) 戻り値 NaN NaN +0 +0 -0 -0 +∞ +∞ -∞ -∞ (-1) < x < 0 -0
例
console.log(Math.ceil(1.1)); // 出力:2
console.log(Math.ceil(-1.9)); // 出力:-1
console.log(Math.ceil(NaN)); // 出力:NaN
console.log(Math.ceil(+0)); // 出力:0
console.log(Math.ceil(-0)); // 出力:-0
console.log(Math.ceil(+Infinity)); // 出力:Infinity
console.log(Math.ceil(-Infinity)); // 出力:-Infinity
Math.floor【小数点以下切り下げ:floor】メソッド
メモ
- 小数点以下を切り下げ
- 関連:
構文
Math.floor( x )- x:数値
- 小数点以下を切り下げた整数値
x (参考値) 戻り値 NaN NaN +0 +0 -0 -0 +∞ +∞ -∞ -∞ 0 < x < 1 +0
例
console.log(Math.floor(1.9)); // 出力:1
console.log(Math.floor(-1.1)); // 出力:-2
console.log(Math.floor(NaN)); // 出力:NaN
console.log(Math.floor(+0)); // 出力:0
console.log(Math.floor(-0)); // 出力:-0
console.log(Math.floor(+Infinity)); // 出力:Infinity
console.log(Math.floor(-Infinity)); // 出力:-Infinity
Math.abs【絶対値:absolute value】メソッド
メモ
構文
Math.abs( x )- x:絶対値を求める数値
- 絶対値
x (参考値) 戻り値 NaN NaN −0 +0 −∞ +∞
例
console.log(Math.abs(+3.5)); // 出力:3.5
console.log(Math.abs(-3.5)); // 出力:3.5
console.log(Math.abs(NaN)); // 出力:NaN
console.log(Math.abs(+0)); // 出力:0
console.log(Math.abs(-0)); // 出力:0
console.log(Math.abs(+Infinity)); // 出力:Infinity
console.log(Math.abs(-Infinity)); // 出力:Infinity
関連
- ECMAScript 5.1 (英語)
- ECMAScript 2015 (6) (英語)
- ECMAScript 2016 (7) (英語)