El java.lang.Math.ronda() es una función matemática incorporada que devuelve el largo más cercano al argumento. El resultado se redondea a un número entero sumando 1/2 , tomando el piso del resultado después de agregar 1/2 y emitiendo el resultado para escribirlo largo.
- Si el argumento es No, el resultado es 0.
- Si el argumento es infinito negativo o cualquier valor menor o igual al valor de Entero.MIN_VALUE , el resultado es igual al valor de Integer.MIN_VALUE.
- Si el argumento es infinito positivo o cualquier valor mayor o igual al valor de Entero.MAX_VALUE , el resultado es igual al valor de Integer.MAX_VALUE.
Sintaxis:
public static int round(float val) Parameter: val - floating-point value to be rounded to an integer.>
Devoluciones:
El método devuelve el valor del argumento redondeado al valor int más cercano.
Ejemplo: Para mostrar el funcionamiento de la función 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));> > >}> }> |
>
>
Producción:
4568 -3421 9223372036854775807>