Number 메서드
Number.insInteger
- arguments: 정수 여부를 검사
- return value: boolean
Number.isInteger(0);
Number.isInteger(Math.PI);
Number.isInteger([1]);
Number.isInteger('100');
parseInt / parseFloat
- arguments: 형변환하기 위해 parsing될 값, (진법 = 10)
- return value: 정수 또는 실수
parseInt('1');
parseInt('1.1');
parseInt('string');
parseFloat('3.14');
parseInt("0xF", 16);
parseInt("1", 10);
parseInt("10", 8);
parseInt("111", 2);
toFixed
- arguments: (소숫점 뒤에 나타낼 자릿수 = 0)
- return value: 숫자를 나타내는 문자열
const realNumber = 12345.6789;
realNumber.toFixed();
realNumber.toFixed(1);
realNumber.toFixed(6);
Math 메서드
Math.max / Math.min
- arguments: 숫자, 숫자, 숫자, ...
- return value: 가장 큰 / 작은 값
Math.min(5, 100, 25);
Math.max(5, 100, 25);
Math.max('hello', 'world');
Math.floor / Math.round
- arguments: 숫자
- return value: 주어진 숫자를 내림 / 반올림한 값
Math.floor(456.789);
Math.floor(-456.789);
Math.round(234.567);
Math.round(-234.567);
Math.random
- arguments: 없음
- return value: 0과 1 미만의 난수
Math.random();
Math.abs
- arguments: 숫자
- return value: 주어진 숫자의 절대값
Math.abs(-3);
Math.abs('-3');
Math.abs(null);
Math.abs([2]);
Math.abs([1,2]);
Math.abs({});
Math.abs('string');
Math.abs();
Math.sqrt
- arguments: 숫자
- return value: 제곱근
Math.sqrt(256);
Math.sqrt(2);
Math.sqrt(-1);
Math.pow
- arguments: 밑 (base), 지수 (exponent)
- return value: base^exponent
Math.pow(5, 2);
Math.pow(5, 3);
Math.pow(-5, 3);
Math.pow(2, 0.5);
Math.pow(8, -1/3);