Java - Math.toDegrees() Method



Description

The Java Math toDegrees(double angrad) converts an angle measured in radians to an approximately equivalent angle measured in degrees. The conversion from radians to degrees is generally inexact; users should not expect cos(toRadians(90.0)) to exactly equal 0.0.

Declaration

Syntax

public static double toDegrees(double d)

Parameters

Here is the detail of parameters −

  • d − A double data type.

Return Value

  • This method returns a double value.

Example 1

In this example, we're showing the usage of Math.toDegrees() method to get the degrees of two double numbers. We've created two double variables x and y and initialized them with a given values. Then using Math.toDegrees() method we've printed the corresponding degree values.

public class Test { 
   public static void main(String args[]) {
      double x = 45.0;
      double y = 30.0;

      System.out.println( Math.toDegrees(x) );
      System.out.println( Math.toDegrees(y) );
   }
}

This will produce the following result −

Output

2578.3100780887044
1718.8733853924698

Example 2

In this example, we're showing the usage of Math.toDegrees() method to get the degrees of two float numbers. We've created two float variables x and y and initialized them with a given values. Then using Math.toDegrees() method we've printed the corresponding degree values.

public class Test { 
   public static void main(String args[]) {
      float x = (float)45.0;
      float y = (float)30.0;

      System.out.println( Math.toDegrees(x) );
      System.out.println( Math.toDegrees(y) );
   }
}

This will produce the following result −

Output

2578.3100780887044
1718.8733853924698

Example 3

In this example, we're showing the usage of Math.toDegrees() method to get the degrees of a zero value. We've created two float variables x and y and initialized them with a given values. Then using Math.toDegrees() method we've printed the corresponding degree values.

public class Test { 
   public static void main(String args[]) {
      float x = (float)0.0;
      float y = (float)-0.0;

      System.out.println( Math.toDegrees(x) );
      System.out.println( Math.toDegrees(y) );
   }
}

This will produce the following result −

Output

0.0
-0.0
java_numbers.htm
Advertisements