Java round() method


Java Number类Java Number class


rint() method returns the closest int or long value.

Grammar

This method has the following syntax formats:

long round(double d)int round(float f)

Parameters

  • d - - Native data type of double or float

  • f -- Native data type of float

##Return value

Returns the closest int or long value, and the method will specify the returned data type.

Example

public class Test{public static void main(String args[]){double d = 100.675;double e = 100.500;float f = 100;float g = 90f;System.out.println(Math.round(d));System.out.println(Math.round(e)); 
		System.out.println(Math.round(f)); 
		System.out.println(Math.round(g)); 
	}}

Compile the above program and the output result is:

10110110090


Java Number classJava Number类