Math.floor(), Math.ceil(), Math.round()

Math floor는 어떤 수보다 크지 않은 최대의 정수를 반환합니다. Math ceil는 어떤 수보다 작지 않은 최소의 정수를 반환합니다. Math round는 어떤 수와 가장 가까운 정수를 반환합니다.

Math.floor()

Math.floor()는 어떤 수보다 크지 않은 최대의 정수를 반환합니다.

 

기본형

Math.floor( Number )
  • Number에는 숫자가 들어갑니다.

 

예제

document.write( '<p>Math.floor( 1.6 ) : ' + Math.floor( 1.6 ) + '</p>' );
document.write( '<p>Math.floor( 1.2 ) : ' + Math.floor( 1.2 ) + '</p>' );
document.write( '<p>Math.floor( 1.0 ) : ' + Math.floor( 1.0 ) + '</p>' );
document.write( '<p>Math.floor( -1.2 ) : ' + Math.floor( -1.2 ) + '</p>' );
document.write( '<p>Math.floor( -1.6 ) : ' + Math.floor( -1.6 ) + '</p>' );
document.write( '<p>Math.floor( -2.0 ) : ' + Math.floor( -2.0 ) + '</p>' );

로딩 중... 잠시만 기다려주세요.
자바스크립트를 허용해주세요.

 

Math.ceil()

Math.ceil()는 어떤 수보다 작지 않은 최소의 정수를 반환합니다.

 

기본형

Math.ceil( Number )
  • Number에는 숫자가 들어갑니다.

 

예제

document.write( '<p>Math.ceil( 1.6 ) : ' + Math.ceil( 1.6 ) + '</p>' );
document.write( '<p>Math.ceil( 1.2 ) : ' + Math.ceil( 1.2 ) + '</p>' );
document.write( '<p>Math.ceil( 1.0 ) : ' + Math.ceil( 1.0 ) + '</p>' );
document.write( '<p>Math.ceil( -1.2 ) : ' + Math.ceil( -1.2 ) + '</p>' );
document.write( '<p>Math.ceil( -1.6 ) : ' + Math.ceil( -1.6 ) + '</p>' );
document.write( '<p>Math.ceil( -2.0 ) : ' + Math.ceil( -2.0 ) + '</p>' );

로딩 중... 잠시만 기다려주세요.
자바스크립트를 허용해주세요.

 

Math.round()

Math.round()는 어떤 수와 가장 가까운 정수를 반환합니다. 어떤 수의 소수 부분이 0.5인 경우 가까운 큰 정수를 반환합니다.

 

기본형

Math.round( Number )
  • Number에는 숫자가 들어갑니다.

 

예제

document.write( '<p>Math.round( 1.6 ) : ' + Math.round( 1.6 ) + '</p>' );
document.write( '<p>Math.round( 1.5 ) : ' + Math.round( 1.5 ) + '</p>' );
document.write( '<p>Math.round( 1.2 ) : ' + Math.round( 1.2 ) + '</p>' );
document.write( '<p>Math.round( 1.0 ) : ' + Math.round( 1.0 ) + '</p>' );
document.write( '<p>Math.round( -1.2 ) : ' + Math.round( -1.2 ) + '</p>' );
document.write( '<p>Math.round( -1.5 ) : ' + Math.round( -1.5 ) + '</p>' );
document.write( '<p>Math.round( -1.6 ) : ' + Math.round( -1.6 ) + '</p>' );
document.write( '<p>Math.round( -2.0 ) : ' + Math.round( -2.0 ) + '</p>' );

로딩 중... 잠시만 기다려주세요.
자바스크립트를 허용해주세요.

Post a Comment