The Math.toRadians() method converts an angle measured in degrees to an approximately equivalent angle measured in radians using the scaling factor Math.PI / 180.0.
Required Gateway for Circular Trigonometry: Converts degree angles into radians for Math.sin(), Math.cos(), and Math.tan(). For converting radian outputs from Math.asin(), Math.acos(), and Math.atan() back into degrees, use Math.toDegrees().
Declared as a static method in java.lang.Math:
// Formal signature of Math.toRadians() in java.lang.Math
public static double toRadians(double angdeg)
| Signature Element | Type | Description & Operational Rule |
|---|---|---|
angdeg |
double |
An angle measured in degrees (any real number, positive or negative). |
| Return Value | double |
The measurement of angdeg in radians: angdeg / 180.0 * Math.PI. |
| Unit Ratio | Constant | 1.0 degree ≈ 0.017453292519943295 radians; 180.0 degrees = pi radians. |
Converting cardinal degree measurements and negative degree angles into radians:
System.out.println(Math.toRadians(180.0)); // 3.141592653589793 (Math.PI)
System.out.println(Math.toRadians(90.0)); // 1.5707963267948966 (Math.PI / 2)
System.out.println(Math.toRadians(0.0)); // 0.0
System.out.println(Math.toRadians(1.22)); // 0.02129301687433082
System.out.println(Math.toRadians(-120.0)); // -2.0943951023931953Terminal Output:
3.141592653589793
1.5707963267948966
0.0
0.02129301687433082
-2.0943951023931953
Passing degree values directly into Math.sin(30) treats 30 as 30 radians (yielding -0.988 instead of 0.5). Always convert degrees with Math.toRadians() first:
System.out.println(Math.round(Math.sin(Math.toRadians(30.0)) * 10) / 10.0); // 0.5
System.out.println(Math.round(Math.cos(Math.toRadians(60.0)) * 10) / 10.0); // 0.5
System.out.println(Math.round(Math.tan(Math.toRadians(45.0)) * 10) / 10.0); // 1.0Terminal Output:
0.5
0.5
1.0
Because Math.toRadians() scales by the positive constant Math.PI / 180.0, signed zero, infinities, and NaN are preserved directly:
System.out.println(Math.toRadians(-0.0)); // -0.0
System.out.println(Math.toRadians(Double.POSITIVE_INFINITY)); // Infinity
System.out.println(Math.toRadians(Double.NEGATIVE_INFINITY)); // -Infinity
System.out.println(Math.toRadians(Double.NaN)); // NaNTerminal Output:
-0.0
Infinity
-Infinity
NaN
Because Math.PI is a finite 64-bit approximation of pi, Math.toRadians(180.0) differs from true mathematical pi by 1.2246e-16. Consequently, Math.sin(Math.toRadians(180.0)) returns 1.2246467991473532E-16 rather than exact 0.0:
double sin180 = Math.sin(Math.toRadians(180.0));
System.out.println("Raw sin(toRadians(180)): " + sin180);
System.out.println("Near zero (< 1e-15)? " + (Math.abs(sin180) < 1e-15));Terminal Output:
Raw sin(toRadians(180)): 1.2246467991473532E-16
Near zero (< 1e-15)? true
Summary of degree and radian roles across java.lang.Math:
| Method | Input Unit | Output Unit | Primary Role |
|---|---|---|---|
Math.toRadians(deg) |
Degrees | Radians | Multiplies by Math.PI / 180.0 |
Math.toDegrees(rad) |
Radians | Degrees | Multiplies by 180.0 / Math.PI |
Math.sin(rad) / cos(rad) |
Radians | Ratio [-1, 1] |
Forward trig (pass toRadians output) |
Math.asin(v) / acos(v) |
Ratio [-1, 1] |
Radians | Inverse trig (convert result via toDegrees) |
Converting GPS latitude and longitude degree coordinates into radians via Math.toRadians() to compute surface distance between New Delhi and Mumbai:
public class HaversineDistance {
public static double distanceKm(double lat1, double lon1, double lat2, double lon2) {
double dLat = Math.toRadians(lat2 - lat1);
return 6371.0 * Math.abs(dLat);
}
public static void main(String[] args) {
System.out.println(String.format("%.1f km", distanceKm(28.61, 77.21, 19.08, 72.88)));
}
}Terminal Output:
1059.7 km
Rotating a 2D point (x, y) counter-clockwise by an angle specified in degrees:
public class PointRotation2D {
public static void main(String[] args) {
double rad = Math.toRadians(90.0);
System.out.println(String.format("(%.1f, %.1f)", 10 * Math.cos(rad), 10 * Math.sin(rad)));
}
}Terminal Output:
(0.0, 10.0)
Do not call Math.toRadians() on outputs from Math.atan(), which are already in radians.
Hyperbolic methods (Math.sinh(), Math.cosh(), and Math.tanh()) operate on hyperbolic area parameters, not circular angles. Only use Math.toRadians() with circular trig methods.
Compile and run this verification class in any Java environment:
public class MathToRadiansFullDemo {
public static void main(String[] args) {
if (Math.toRadians(180.0) == Math.PI && Math.toRadians(0.0) == 0.0) {
System.out.println("Check 1 Passed: 180 deg maps to Math.PI.");
}
double d = 135.0;
if (Math.abs(Math.toDegrees(Math.toRadians(d)) - d) < 1e-12) {
System.out.println("Check 2 Passed: Round-trip toRadians -> toDegrees verified.");
}
System.out.println("All Math.toRadians() verification checks passed!");
}
}Terminal Output:
Check 1 Passed: 180 deg maps to Math.PI.
Check 2 Passed: Round-trip toRadians -> toDegrees verified.
All Math.toRadians() verification checks passed!
Math.toRadians(1.0) returns 0.017453292519943295 radians (Math.PI / 180.0).
No. Math.toRadians(720.0) returns 4 * Math.PI (12.566370614359172). If you want the angle normalized into [0, 2*PI), normalize the degree input with deg % 360.0 first.
Because pi is irrational, multiplying by the 64-bit float Math.PI / 180.0 introduces a tiny rounding error of up to half a unit in the last place (ULP).
Use Math.toDegrees(angrad), which multiplies the radian value by 180.0 / Math.PI.
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.