-
[JS] 소수점을 버리고 자연수를 얻는 방법Web/JS 2022. 1. 17. 10:39SMALL
- 1. Math.round() : 반올림
- 2. Math.ceil() : 올림
- 3. Math.floor(): 내림
- cf. Math.random() : 0~1 범위 내의 랜덤한 수 추출
사용 예시
Math.floor(Math.random()*10) Maht.ceil(Math.random()*10) //0~10 사이의 랜덤한 수 function randomRange(myMin, myMax) { return Math.floor(Math.random() * (myMax-myMin+1))+myMin; } //최솟값,최댓값 범위 내의 랜덤한 수
반응형'Web > JS' 카테고리의 다른 글
[JS] Closure (0) 2022.05.12 [JS] Constructor Function (0) 2022.05.06 [JS] 정규표현식(Regular Expressions) (0) 2022.02.11