The Math.toDegrees() method converts an angle measured in radians to an approximately equivalent angle measured in degrees using the scaling factor 180.0 / Math.PI.
Essential Companion to Inverse Trigonometry: Converts radian outputs from Math.asin(), Math.acos(), and Math.atan() into degrees. For the reverse conversion before calling Math.sin(), Math.cos(), or Math.tan(), use Math.toRadians().
Declared as a static method in java.lang.Math:
// Formal signature of Math.toDegrees() in java.lang.Math
public static double toDegrees(double angrad)
| Signature Element | Type | Description & Operational Rule |
|---|---|---|
angrad |
double |
An angle measured in radians (any real number, unbounded). |
| Return Value | double |
The measurement of angrad in degrees: angrad * 180.0 / Math.PI. |
| Unit Ratio | Constant | 1.0 radian ≈ 57.29577951308232 degrees; pi radians = 180.0 degrees. |
Converting cardinal multiples of Math.PI and arbitrary radian inputs into degrees:
System.out.println(Math.toDegrees(Math.PI)); // 180.0
System.out.println(Math.toDegrees(Math.PI / 2)); // 90.0
System.out.println(Math.toDegrees(1.0)); // 57.29577951308232 (1 rad)
System.out.println(Math.toDegrees(2.0)); // 114.59155902616465
System.out.println(Math.toDegrees(-1.22)); // -69.90085100596043
System.out.println(Math.toDegrees(0.0)); // 0.0Terminal Output:
180.0
90.0
57.29577951308232
114.59155902616465
-69.90085100596043
0.0
All Java inverse trigonometric methods (Math.asin(), Math.acos(), and Math.atan()) return angles in radians. Wrap their return values in Math.toDegrees() to obtain degrees:
// Inverse trig returns radians -> convert to degrees with Math.toDegrees()
System.out.println(Math.round(Math.toDegrees(Math.asin(0.5)))); // 30
System.out.println(Math.round(Math.toDegrees(Math.acos(0.5)))); // 60
System.out.println(Math.round(Math.toDegrees(Math.atan(1.0)))); // 45Terminal Output:
30
60
45
Because Math.toDegrees() multiplies its input by the positive finite constant 180.0 / Math.PI, signed zero, infinities, and NaN propagate directly:
System.out.println(Math.toDegrees(-0.0)); // -0.0
System.out.println(Math.toDegrees(Double.POSITIVE_INFINITY)); // Infinity
System.out.println(Math.toDegrees(Double.NEGATIVE_INFINITY)); // -Infinity
System.out.println(Math.toDegrees(Double.NaN)); // NaNTerminal Output:
-0.0
Infinity
-Infinity
NaN
The conversion from radians to degrees is generally inexact because Math.PI is a 64-bit binary approximation of irrational pi. Always use epsilon tolerance or Math.round() rather than == when checking converted angles:
double deg60 = Math.toDegrees(Math.PI / 3.0);
System.out.println("Raw toDegrees(PI/3): " + deg60);
System.out.println("Equals exact 60.0? " + (deg60 == 60.0));
System.out.println("Epsilon (< 1e-12): " + (Math.abs(deg60 - 60.0) < 1e-12));Terminal Output:
Raw toDegrees(PI/3): 59.99999999999999
Equals exact 60.0? false
Epsilon (< 1e-12): true
How Math.toDegrees() fits into the complete Java trigonometric workflow:
| Method | Input Unit | Output Unit | Primary Role |
|---|---|---|---|
Math.toDegrees(rad) |
Radians | Degrees | Multiplies by 180.0 / Math.PI |
Math.toRadians(deg) |
Degrees | Radians | Multiplies by Math.PI / 180.0 |
Math.sin(rad) / cos(rad) |
Radians | Ratio [-1, 1] |
Forward circular trigonometry |
Math.asin(v) / acos(v) |
Ratio [-1, 1] |
Radians | Inverse trig (pass result to toDegrees) |
Converting a 2D vector (dx, dy) into a positive [0.0, 360.0) heading in degrees:
public class CompassBearing {
public static double toCompassDegrees(double dy, double dx) {
return (Math.toDegrees(Math.atan2(dy, dx)) + 360.0) % 360.0;
}
public static void main(String[] args) {
System.out.println("Heading: " + toCompassDegrees(-1.0, -1.0) + " deg");
}
}Terminal Output:
Heading: 225.0 deg
Converting a radian measurement into cartographic DD deg MM' SS.ss" notation:
public class DmsFormatter {
public static String radToDms(double rad) {
double d = Math.abs(Math.toDegrees(rad));
int deg = (int) d, min = (int) ((d - deg) * 60);
double sec = (((d - deg) * 60) - min) * 60;
return String.format("%d deg %02d' %05.2f"", deg, min, sec);
}
public static void main(String[] args) {
System.out.println(radToDms(1.0));
}
}Terminal Output:
57 deg 17' 44.81"
Math.toDegrees() is a pure linear scaling function (angrad * 180.0 / Math.PI). Passing 4 * Math.PI returns 720.0, not 0.0. Use ((deg % 360.0) + 360.0) % 360.0 if you need a bounded [0, 360) angle.
When you have a 45-degree angle and want its sine, calling Math.sin(Math.toDegrees(45)) is backwards! Always use Math.toRadians(45) before calling Math.sin().
Compile and run this verification class in any Java environment:
public class MathToDegreesFullDemo {
public static void main(String[] args) {
if (Math.toDegrees(Math.PI) == 180.0 && Math.toDegrees(Math.PI / 2.0) == 90.0) {
System.out.println("Check 1 Passed: PI and PI/2 map to 180.0 and 90.0.");
}
double r = 2.5;
if (Math.abs(Math.toRadians(Math.toDegrees(r)) - r) < 1e-15) {
System.out.println("Check 2 Passed: Round-trip toDegrees -> toRadians verified.");
}
System.out.println("All Math.toDegrees() verification checks passed!");
}
}Terminal Output:
Check 1 Passed: PI and PI/2 map to 180.0 and 90.0.
Check 2 Passed: Round-trip toDegrees -> toRadians verified.
All Math.toDegrees() verification checks passed!
Math.toDegrees(1.0) returns 57.29577951308232 degrees (180.0 / Math.PI).
Yes. Passing a negative radian value returns a negative degree value of the exact same magnitude (Math.toDegrees(-Math.PI) == -180.0).
Because IEEE 754 floating-point division and multiplication by Math.PI can introduce a 1-ULP rounding difference (such as 59.99999999999999). Always compare with Math.abs(deg - 60.0) < 1e-12.
Use Math.toRadians(angdeg), which multiplies the degree measurement by Math.PI / 180.0.
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.