0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Mathオブジェクト JavaScript

Last updated at Posted at 2024-08-26

数値オブジェクト

・インスタンス化しないで使用できる
・Math.を使用

円周率

Math.PI

単数を処理するメソッド

小数点以下切り上げ

Math.ceil(x)

切り捨て

Math.floor(x)

四捨五入

Math.round(x)

引数の絶対値を求めるメソッド

Math.abs(x)

最大値・最小値

Math.max(x,x1,,,)
Math.min(x,x1,,,)

乱数を出力

0~a(aの値は含まない)を返す。

Math.random()
function getnum(a){
    let ransu =Math.random()*(a+1);
    return Math.floor(ransu);
}

10までの数字がランダムに出力

console.log(getnum(10));
//-> 8

参考書籍

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?