Groovy – round()

  • Post author:
  • Post category:Groovy
  • Post comments:1 Comment
Round

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

Syntax

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

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

Following is an example of the usage of this method −

class Example { 
   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)); 
   } 
}

When we run the above program, we will get the following result −

101 
101 
100 
90

Previous Page:-Click Here

This Post Has One Comment

Leave a Reply