WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

Java - round() Method


Returns the closest long or int, as indicated by the method's return type to the argument.


Syntax

This method has the following variants −

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

Parameters

Here is the detail of parameters −

  • d − A double or float primitive data type.

  • f − A float primitive data type.

Return Value

  • This method returns the closest long or int, as indicated by the method's return type, to the argument.

Example

public class Test { 

   public static void main(String args[]) {
      double d = 200.675;
      double e = 100.500;
      float f = 200;
      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)); 
   }
}
Run example »