Javascript

Math.round()

근혁 2022. 5. 1. 23:15

Math.round()

반올림 : 반환(숫자)

{
1.    기본값 : 1.34
      메서드 : round(1.34)

      document.querySelector(".sample1_R1").innerHTML = Math.round(1.34);
      //결과값 : 1

2.    기본값 : 2.34
      메서드 : round(1.64)	

      document.querySelector(".sample1_R2").innerHTML = Math.round(1.64);
      //결과값 : 2

3.    기본값 : 3.34
      메서드 : round(1.5)

      document.querySelector(".sample1_R3").innerHTML = Math.round(1.5);
      //결과값 : 2

4.    기본값 : 3.34
      메서드 : round(1.34)

      document.querySelector(".sample1_R4").innerHTML = Math.round(1.34);
      //결과값 : 1

5.    기본값 : 3.34
      메서드 : round(-1.64)	

      document.querySelector(".sample1_R5").innerHTML = Math.round(-1.64);
      //결과값 : -2

6.    기본값 : 3.34	
      메서드 : round(-1.5)

      document.querySelector(".sample1_R6").innerHTML = Math.round(-1.5);
      //결과값 : -1 
}