What is Math.toDegrees() in Java?

toDegrees() is a static method that is used to convert a radian angle into approximately equivalent degree measures.

Note: toDegrees() is an approximate conversion, so it may contain some errors. For example, sin(toRadians(90.0)) cannot be exactly equal to 1.0.

Formula to convert degrees to radians

Syntax


static double toDegrees(double radianAngle)

Parameters

  • radianAngle: An angle in radian measures.

Return value

toDegrees() returns the approximate angle value in degrees, which is of type double.

Code

In lines 11 and 13, we use Math.toDegrees() to convert argument values x and y in radian measure. We can also use this method to make our calculations easily, like in trigonometric functions.

// Load Math library
import java.lang.Math;
// Main class
public class EdPresso {
public static void main(String[] args) {
// get two double numbers numbers
double x = 30;
double y = -90;
// convert them in degrees
x = Math.toDegrees(x);
System.out.println("Math.toDegrees(x)= " + x);
y = Math.toDegrees(y);
System.out.println("Math.toDegrees(y)= " + y);
// Additional use in Trignomatric Functions
System.out.println("Math.sin(" + x + ")= " + Math.sin(x));
System.out.println("Math.sin(" + y + ")= " + Math.sin(y));
}
}
New on Educative
Learn to Code
Learn any Language as a beginner
Develop a human edge in an AI powered world and learn to code with AI from our beginner friendly catalog
🏆 Leaderboard
Daily Coding Challenge
Solve a new coding challenge every day and climb the leaderboard

Free Resources