Java Math toDegrees()

Overview
An angle measured in radians can be converted to an approximately equivalent angle in degrees using the toDegrees() method defined in the Math class.
- toDegrees() method returns NaN if the argument is NaN(Not a Number).
- toDegrees() method returns zero with the same sign as the argument if the argument is zero.
- toDegrees() method returns Infinity with the same sign as the input if the argument is Infinity.
Build an AI-First Career, Master the Complete Skillset
Choose from our industry-leading programs designed for career success
Modern Software and AI Engineering Program
Master full-stack development with AI integration
+1000 moreModern Data Science and ML with specialisation in AI
Advanced data science techniques with AI specialization
+1000 moreAdvanced AIML with Specialisation in Agentic AI
Deep dive into AIML with focus on Agentic systems
+1000 moreDevOps, Cloud & AI Platform Engineering
Build and manage AI-powered cloud infrastructure
+1000 moreAI Engineering Advanced Certification by IIT-Roorkee
Premier AI engineering certification from IIT-Roorkee
AI Forward Deployed Engineer Program
Full-stack engineering, production AI and client-facing consulting
+1000 moreSyntax of Math toDegrees()in Java
The syntax of the toDegrees() method is:
Parameters of Math toDegrees() in Java
The toDegrees() method takes only one parameter.
- angle: The angle in radians that needs to be changed to degrees.
Return Value of Math toDegrees() in Java
- Returns the angle measured in degrees
- Return type is double
Exceptions of Math toDegrees() in Java
Math.toDegrees() does NOT throw any exception.
How Scaler Transformed Careers in Different Fields
Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.
Example
Note: To convert an angle in radians to degrees we simply multiply it with 180/π.
In this example we are going to see how to use/call Math.toDegrees() method in java.
Output:
Explanation:
- In above code we have simply converted angle in radian to angle in degrees using Math.toDegrees() method of the Math class.
- As we know, 3.14, which is roughly equal to π, is very close to 180 degrees.
What is Math toDegrees() in Java?
An angle measured in radians is converted to a roughly comparable angle measured in degrees using the Math.toDegrees() method.
- This method will return NaN if the argument is NaN
- This method will return zero with the same sign as the argument if the argument is zero.
- This method will return Infinity with the same sign as the input if the argument is Infinity.
Turn Learning into Career Growth
More Examples
Example 1
In this example, we are going to see how to convert radians to degrees using toDegrees() method in Java:
Output:
Explanation:
- In the above Example, we have converted the angle in radians to degrees using toDegrees() method in Java.
- We have initialized x and y as 1.5708 and -0.0, and converted them into degrees.
Example 2
In this example, we are going to use toDegrees() method in java with NaN.
Output:
Explanation:
- As we have discussed above that toDegrees() will return NaN when a NaN is passed as argument.
Note: Square of a negative number is NaN in Java.
Example-3
In this example, we are going to see how to use Math.toDegrees() in java with Infinity.
Output:
Explanation:
- As we discussed above that this method will return Infinity with the same sign as the input if the argument is Infinity.
- So in the above code Infinity is printed when POSITIVE_INFINITY is passed and -Infinity is printed when NEGATIVE_INFINITY is passed.
Conclusion
- An angle measured in radians is converted to a roughly comparable angle measured in degrees using the toDegrees() method defined in Math class.
- This method will return NaN if the argument is NaN.
- This method will return zero with the same sign as the argument if the argument is zero.
- This method will return Infinity with the same sign as the argument if the argument is Infinity.