자바스크립트는 다른 언어와는 달리 쉬운 Math 메소드를 제공하고 있다.
가장 많이 쓰이는 Math 메소드는 다음과 같다.
- Math.pow()
- Math.min()
- Math.max()
- Math.round()
- Math.floor()
- Math.ceil()
- Math.sqrt()
- Math.random()
Math.pow()
Math.pow(5,2);
->25
Math.min()
Math.min(1,2,3,4,5);
->1
Math.max()
Math.max(1,2,3,4,5);
->5
Math.round()
Math.round(10.7);
->11
Math.floor()
Math.floor(10.6);
->10
Math.ceil()
Math.ceil(10.1);
->11
Math.sqrt()
Math.sqrt(9);
->3
Math.random()
Math.random();
->0부터 1.0 사이의 랜덤한 숫자
'프론트엔드 > JavaScript' 카테고리의 다른 글
[JS] JSON.parse()와 JSON.stringify() 사용법 (0) | 2024.08.13 |
---|