Der java.lang.Math.round() ist eine integrierte mathematische Funktion, die die dem Argument am nächsten kommende Länge zurückgibt. Das Ergebnis wird durch Addition auf eine ganze Zahl gerundet 1/2 , nimmt das Wort des Ergebnisses nach der Addition von 1/2 und wandelt das Ergebnis in den Typ long um.
- Wenn das Argument ist NEIN, das Ergebnis ist 0.
- Wenn das Argument negativ unendlich oder ein beliebiger Wert ist, der kleiner oder gleich dem Wert von ist Ganzzahl.MIN_VALUE , das Ergebnis ist gleich dem Wert von Integer.MIN_VALUE.
- Wenn das Argument positiv unendlich oder ein beliebiger Wert ist, der größer oder gleich dem Wert von ist Ganzzahl.MAX_VALUE , das Ergebnis ist gleich dem Wert von Integer.MAX_VALUE.
Syntax:
public static int round(float val) Parameter: val - floating-point value to be rounded to an integer.>
Kehrt zurück:
Die Methode gibt den Wert des Arguments zurück, gerundet auf den nächsten int-Wert.
Beispiel: Um die Funktionsweise der Funktion java.lang.Math.round() zu zeigen
// 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));> > > }> }> |
>
>
Ausgabe:
4568 -3421 9223372036854775807>