Tutorials Point


  Java Basics
  Java Object Oriented
  Java Advanced
  Java Useful References
  Java Useful Resources
  Selected Reading

© 2011 TutorialsPoint.COM


  Home     References     Discussion Forums     About TP  

Java - round() Method


previous next AddThis Social Bookmark Button


Description:

The method round returns the closest long or int, as given by the methods return type.

Syntax:

This method has following variants:

long round(double d)

int round(float f)

Parameters:

Here is the detail of parameters:

  • A double or float primitive data type

Return Value :

  • 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 = 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)); 
			}
}

This produces following result:

101
101
100
90


previous next Printer Friendly



  

Advertisement

Online Image Processing

Indian Baby Names