Groovy Operators

Control Statements

Groovy File Handling

Groovy Error & Exceptions

Groovy Multithreading

Groovy Synchronization

Groovy - toRadians() method



The toRadians() method converts the argument value to radians.

Syntax

double toRadians(double d)

Parameters

  • d − A double data type.

Return Value

This method returns a double value.

Example - Usage of toRadians() method for a positive double values

Following is an example of the usage of this method −

Example.groovy

class Example {     
   static void main(String[] args){
      double x = 45.0;
      double y = 30.0;
		
      println( Math.toRadians(x) );
      println( Math.toRadians(y) );
   } 
}

Output

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

0.7853981633974483
0.5235987755982988

Example - Usage of toRadians() method for zero double values

Following is an example of the usage of this method −

Example.groovy

class Example {     
   static void main(String[] args){
      double x = 0.0;
      double y = 0.0;
		
      println( Math.toRadians(x) );
      println( Math.toRadians(y) );
   } 
}

Output

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

0.0
0.0

Example - Usage of toRadians() method for negative double values

Following is an example of the usage of this method −

Example.groovy

class Example {     
   static void main(String[] args){
      double x = -45.0;
      double y = -30.0;
		
      println( Math.toRadians(x) );
      println( Math.toRadians(y) );
   } 
}

Output

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

-0.7853981633974483
-0.5235987755982988
groovy_numbers.htm
Advertisements