.toDegrees()

Anonymous contributor's avatar
Anonymous contributor
Published Oct 31, 2022
Contribute to Docs

The .toDegrees() method converts an angle, measured in radians, to an approximately equivalent angle, measured in degrees.

Syntax

Math.toDegrees(angle)

The data type of the angle parameter and return value of the .toDegrees() method is a double.

Some edge cases for the .toDegrees() method include the following:

  • If the argument is NaN, this method will return NaN.
  • If the argument is zero, this method will return zero with the same sign as the argument.
  • If the argument is infinity, this method will return infinity with the same sign as the argument.

Example

The following example demonstrates the .toDegrees() method being applied to two variables:

// TestDegree.java
public class TestDegrees {
public static void main(String args[]) {
double x = 0.5235987756;
System.out.println(Math.toDegrees(x));
double y = 1.0471975512;
System.out.println(Math.toDegrees(y));
}
}

This results in the following output:

30.0
60.0

All contributors

Contribute to Docs

Learn Java on Codecademy