Notice
Recent Posts
Recent Comments
Link
솔미는 성장중
[JS] 표준 내장 객체 : 수학 본문
728x90
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math
Math.abs()
주어진 숫자의 절댓값을 반환
Math.abs(-Infinity); // Infinity
Math.abs(-1); // 1
Math.abs(-0); // 0
Math.abs(0); // 0
Math.abs(1); // 1
Math.abs(Infinity); // Infinity
Math.ceil()
주어진 숫자를 올림해 정수를 반환
Math.ceil(-Infinity); // -Infinity
Math.ceil(-7.004); // -7
Math.ceil(-4); // -4
Math.ceil(-0.95); // -0
Math.ceil(-0); // -0
Math.ceil(0); // 0
Math.ceil(0.95); // 1
Math.ceil(4); // 4
Math.ceil(7.004); // 8
Math.ceil(Infinity); // Infinity
Math.floor()
주어진 숫자를 내림해 정수를 반환
Math.floor(-Infinity); // -Infinity
Math.floor(-45.95); // -46
Math.floor(-45.05); // -46
Math.floor(-0); // -0
Math.floor(0); // 0
Math.floor(4); // 4
Math.floor(45.05); // 45
Math.floor(45.95); // 45
Math.floor(Infinity); // Infinity
Math.round()
주어진 숫자를 반올림해 정수를 반환
Math.round(-Infinity); // -Infinity
Math.round(-20.51); // -21
Math.round(-20.5); // -20
Math.round(-0.1); // -0
Math.round(0); // 0
Math.round(20.49); // 20
Math.round(20.5); // 21
Math.round(42); // 42
Math.round(Infinity); // Infinity
Math.max()
주어진 숫자 중 가진 큰 숫자를 반환
Math.min()
주어진 숫자 중 가진 작은 숫자를 반환
Math.pow()
주어진 숫자의 거듭제곱한 값을 반환
Math.pow(base, exponent)
console.log(Math.pow(7, 3));
// Expected output: 343
console.log(Math.pow(4, 0.5));
// Expected output: 2
console.log(Math.pow(7, -2));
// Expected output: 0.02040816326530612
// (1/49)
console.log(Math.pow(-7, 0.5));
// Expected output: NaN
Math.random()
숫자 0 이상, 1미만의 난수 반환
728x90
'JavaScript > 표준 내장 객체' 카테고리의 다른 글
[JS] 표준 내장 객체 : 객체 (0) | 2023.07.23 |
---|---|
[JS] 표준 내장 객체 : 배열 (0) | 2023.07.20 |
[JS] 표준 내장 객체 : 날짜 (0) | 2023.07.20 |
[JS] 표준 내장 객체 : 숫자 (0) | 2023.07.20 |
[JS] 표준 내장 객체 : 문자 (0) | 2023.07.20 |