Java Math toRadians()

Overview
An angle measured in degrees can be converted into an approximately equivalent angle measured in radians using toRadians() method defined in the java.lang.Math class.
- This method will return NaN(Not a Number) 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 infinite with the same sign as the input if the argument is infinite.
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 toRadians() in Java
The syntax of the toRadians() method is:
Parameters of Math toRadians() in Java
The toRadians() method takes only one parameter.
angle - The angle in degrees that needs to be converted into radians.
Return Value of Math toRadians() in Java
- Returns the angle measured in radians
- Return type is double
Exceptions of Math toRadians() in Java
Math.toRadians() 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 any given angle from the measure of degrees to radians, the value has to be multiplied by π/180.
In this example we are going to see how to use/call Math.toRadians() method in java.
Output:
Explanation:
- In the above code we have simply converted the angle in Degrees to Radians using Math.toRadians() method of Math class.
- As we know, 180 degrees is equal to π radians. Hence, an approximate value of π is printed.
What is Math toRadians() in Java?
An angle measured in Degrees is converted to a roughly comparable angle measured in Radians using the toRadians() method defined in java.lang.Math class. Degrees to Radian conversions are typically not accurate.
- 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 degrees to radians in java using toRadians() method in java.
Output:
Explanation:
In the above code, we have converted 90 and 45 degrees to radians.
Example 2
In this example, we are going to use toRadians() method in java with NaN.
Output:
Explanation:
- As we have discussed above already that toRadians() will return NaN when NaN is passed as argument. So NaN is printed here.
Note: When a negative number is passed as input to Math.sqrt() method, NaN is returned.
Example 3
In this example, we are going to see how to use Math.toRadians() in Java with Infinity as argument.
Output:
Conclusion
- An angle measured in Degrees is converted to a roughly comparable angle measured in Radians using the java.lang.Math.toRadians() method.
- Degrees to Radians conversions are typically not accurate.
- 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.