JavaScript - Math

yeong ·2022년 11월 19일

js

목록 보기
29/49

Math 클래스 함수 : 수학에 관련된 프로퍼티와 메소드 제공하는 클래스 함수

Math.PI : 원주율을 저장한 프로퍼티

alert("Math.PI = "+Math.PI);//Math.PI = 3.141592653589793

Math.ceil(number) : 매개변수로 전달받은 숫자값에 소숫점 자리에 값이 있는 경우 올림 처리된 정수값으로 반환하는 메소드

alert("Math.ceil(12.1) = "+Math.ceil(12.1));//Math.ceil(12.1) = 13

Math.floor(number) : 매개변수로 전달받은 숫자값에 소숫점 자리에 값이 있는 경우 버림(내림) 처리된 정수값으로 반환하는 메소드

alert("Math.floor(12.9) = "+Math.floor(12.9));//Math.floor(12.9) = 12

Math.round(number) : 매개변수로 전달받은 숫자값에 소숫점 자리에 값이 있는 경우 반올림 처리된 정수값으로 반환하는 메소드

alert("Math.round(12.4) = "+Math.round(12.4));//Math.round(12.4) = 12
alert("Math.round(12.5) = "+Math.round(12.5));//Math.round(12.5) = 13

Math.pow(number,number) : 매개변수로 전달받은 숫자값에 대한 제곱근을 계산하여 반환하는 메소드

alert("Math.pow(3,5) = "+Math.pow(3,5));//Math.pow(3,5) = 243

Math.random() : 난수값(0.0<=X<1.0)을 반환하는 메소드

//alert("Math.random() = "+Math.random());
alert("난수값 = "+parseInt(Math.random()*100));//0~99 범위의 난수 발생

0개의 댓글