In Java, Math.toRadians(angdeg) converts an angle from degrees to radians. A full turn is 360 degrees, which is 2 * Math.PI radians, so Math.toRadians(180) is Math.PI (3.141592653589793).
You need it whenever your data is in degrees but the trigonometry methods work in radians: sin, cos, tan, and the results of asin, acos, atan, and atan2. It has been part of java.lang.Math since the early versions of Java.
A static method of the java.lang.Math class, available since the early versions of Java (JDK 1.0). Call it on the class name, as in Math.toRadians(...). No import is needed, because classes in java.lang are always visible.
Syntax
Pass an angle in degrees as a double. The same angle in radians comes back.
Java
double half = Math.toRadians(180); // 3.141592653589793
double quarter = Math.toRadians(90); // 1.5707963267948966
double s = Math.sin(Math.toRadians(30)); // sine of 30 degrees
double manual = degrees * Math.PI / 180; // roughly the same
Call
What it does
Math.toRadians(180)
A half turn: returns Math.PI.
Math.toRadians(90)
A quarter turn: returns 1.5707963267948966.
Math.toRadians(-90)
Returns -1.5707963267948966 (the sign is kept).
Math.toRadians(360)
A full turn: returns 6.283185307179586.
There is only a double version; an int argument is widened. The method does not wrap angles, so Math.toRadians(450) is 7.85..., not the 90 degree equivalent. Take % 360 first if you need that.
Library declarations
Java
// java.lang.Math
public static double toRadians(double angdeg)
Parameters
Parameter
Description
angdeg
An angle measured in degrees.
Return Value
Return Value
Description
double
The same angle in radians. NaN and infinities stay NaN or infinite, and the sign of a zero is kept.
Proportional scaling. Half a turn is PI, so 90 degrees is half of that and 45 degrees is a quarter of it; the results double or halve exactly in binary.
Whole turns. 360 degrees gives 6.283185307179586, which is 2 * Math.PI, and a negative angle simply turns the other way, keeping its minus sign.
Matches the constants. For 90 and 180 degrees the result is exactly Math.PI / 2 and Math.PI, so == happens to work here; for other angles use a tolerance.
Example 2 — Where Is the Hour Hand? Degrees Into Coordinates
The hour hand turns 30 degrees per hour and 0.5 degrees per minute, clockwise from 12. Convert the angle and find the hand tip of a 10 cm hand.
Java
import java.util.Locale;
public class MathToRadiansClock {
public static void main(String[] args) {
int[][] times = {{3, 0}, {6, 0}, {7, 30}, {1, 20}};
for (int[] t : times) {
double degrees = (t[0] % 12) * 30 + t[1] * 0.5;
double rad = Math.toRadians(degrees);
double x = 10 * Math.sin(rad);
double y = 10 * Math.cos(rad);
System.out.println(String.format(Locale.US, "%d:%02d hour hand at %.1f degrees -> tip x=%.2f y=%.2f",
t[0], t[1], degrees, x, y));
}
}
}
Output
3:00 hour hand at 90.0 degrees -> tip x=10.00 y=0.00
6:00 hour hand at 180.0 degrees -> tip x=0.00 y=-10.00
7:30 hour hand at 225.0 degrees -> tip x=-7.07 y=-7.07
1:20 hour hand at 40.0 degrees -> tip x=6.43 y=7.66
How It Works
Time to degrees. At 7:30 the hand has passed seven hours (210 degrees) plus 30 minutes at 0.5 degrees each (15 degrees), so it sits at 225.0 degrees from 12.
Clockwise from the top. Because the angle is measured from 12, x is sin and y is cos, the swapped roles compared with the usual math circle.
Near-zero noise vanishes. At 3:00 and 6:00 one coordinate should be exactly 0, but holds about 6E-16 or 1E-15; %.2f prints it as 0.00.
Example 3 — A Degrees-to-Radians Table in Multiples of PI
Print each angle in radians and as a multiple of Math.PI, then compare with the manual formula.
Java
import java.util.Locale;
public class MathToRadiansTable {
public static void main(String[] args) {
int[] angles = {0, 30, 45, 60, 90, 180, 360};
boolean allClose = true;
for (int deg : angles) {
double rad = Math.toRadians(deg);
allClose = allClose && Math.abs(rad - deg * Math.PI / 180) < 1e-12;
System.out.println(String.format(Locale.US, "%3d degrees = %.4f rad = %.4f * PI", deg, rad, rad / Math.PI));
}
System.out.println("all within 1e-12 of deg * PI / 180? " + allClose);
}
}
Output
0 degrees = 0.0000 rad = 0.0000 * PI
30 degrees = 0.5236 rad = 0.1667 * PI
45 degrees = 0.7854 rad = 0.2500 * PI
60 degrees = 1.0472 rad = 0.3333 * PI
90 degrees = 1.5708 rad = 0.5000 * PI
180 degrees = 3.1416 rad = 1.0000 * PI
360 degrees = 6.2832 rad = 2.0000 * PI
all within 1e-12 of deg * PI / 180? true
How It Works
Dividing by PI shows the fraction. 30 degrees is 1/6 of PI (0.1667), 45 degrees is 1/4 (0.2500), and 60 degrees is 1/3 (0.3333), the familiar textbook multiples.
Four decimals are enough to read. The raw doubles have 16 digits (30 degrees is 0.5235987755982988); %.4f keeps the table short and hides any last-digit difference between Java versions.
Tolerance, not equality.deg * Math.PI / 180 and toRadians can differ in the last digit, so the check allows 1e-12 and reports true for every row.
Frequently Asked Questions
It converts an angle from degrees to radians. Math.toRadians(180) returns Math.PI, 3.141592653589793.
Because sin, cos, and tan expect radians. Math.sin(30) is the sine of 30 radians, about -0.988. Math.sin(Math.toRadians(30)) is the sine of 30 degrees, about 0.5.
Mathematically degrees * PI / 180. Older JDKs compute angdeg / 180.0 * PI and newer ones multiply by a constant, so the last digit of some results can differ between versions.
No. Math.toRadians(450) is 450 degrees expressed in radians, about 7.85. Take degrees % 360 first if you want the equivalent angle within one turn.
Use Math.toDegrees. Math.toDegrees(Math.PI) returns 180.0.