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.
Syntax 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.
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.
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.