logo

예제가 포함된 Java Math round() 메소드


그만큼 java.lang.Math.round() 인수에 가장 가까운 long을 반환하는 내장 수학 함수입니다. 결과는 다음을 추가하여 정수로 반올림됩니다. 1/2 , 1/2을 추가한 후 결과의 바닥을 가져와 결과를 long 형식으로 캐스팅합니다.

  • 인수가 다음과 같은 경우 아니요, 결과는 0입니다.
  • 인수가 음의 무한대이거나 값보다 작거나 같은 값인 경우 정수.MIN_VALUE 이면 결과는 Integer.MIN_VALUE 값과 같습니다.
  • 인수가 양의 무한대이거나 다음 값보다 크거나 같은 값인 경우 정수.MAX_VALUE , 결과는 Integer.MAX_VALUE 값과 같습니다.

통사론:



public static int round(float val) Parameter: val - floating-point value to be rounded to an integer.>

보고:
이 메서드는 가장 가까운 int 값으로 반올림된 인수 값을 반환합니다.

예: java.lang.Math.round() 함수의 작동을 보여주기 위해








// Java program to demonstrate working> // of java.lang.Math.round() method> import> java.lang.Math;> > class> Gfg {> > >// driver code> >public> static> void> main(String args[])> >{> >// float numbers> >float> x =>4567>.9874f;> > >// find the closest int for these floats> >System.out.println(Math.round(x));> > >float> y = ->3421>.134f;> > >// find the closest int for these floats> >System.out.println(Math.round(y));> > >double> positiveInfinity = Double.POSITIVE_INFINITY;> > >// returns the Integer.MAX_VALUE value when> >System.out.println(Math.round(positiveInfinity));> > >}> }>

>

>

산출:

4568 -3421 9223372036854775807>