Groovy Operators

Control Statements

Groovy File Handling

Groovy Error & Exceptions

Groovy Multithreading

Groovy Synchronization

Groovy - rint() method



The method rint() returns the integer that is closest in value to the argument.

Syntax

double rint(double d)

Parameters

d - it accepts a double value as parameter.

Return Value

This method returns the integer that is closest in value to the argument. Returned as a double.

Example - Usage of rint method for a positive double value

Following is an example of the usage of this method −

Example.groovy

class Example { 
   static void main(String[] args){ 
      double d = 100.675;
		
      System.out.println(Math.rint(d)); 
   } 
}

Output

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

101.0 

Example - Usage of rint method for a zero double value

Following is an example of the usage of this method −

Example.groovy

class Example { 
   static void main(String[] args){ 
      double d = 0.0;
		
      System.out.println(Math.rint(d)); 
   } 
}

Output

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

0.0 

Example - Usage of rint method for a negative double value

Following is an example of the usage of this method −

Example.groovy

class Example { 
   static void main(String[] args){ 
      double d = -100.675;
		
      System.out.println(Math.rint(d)); 
   } 
}

Output

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

-101.0 
groovy_numbers.htm
Advertisements