Java Math toDegrees() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
java.lang.Math

Definition

In Java, Math.toDegrees(angrad) converts an angle from radians to degrees. Half a turn is Math.PI radians, so Math.toDegrees(Math.PI) is 180.0.

Most trigonometry methods work in radians, which is hard to read. Use toDegrees to show the answer of asin, acos, atan, or atan2 to a person. 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.toDegrees(...). No import is needed, because classes in java.lang are always visible.

Syntax

Pass an angle in radians as a double. The same angle in degrees comes back.

Java
double half = Math.toDegrees(Math.PI);               // 180.0
double quarter = Math.toDegrees(Math.PI / 2);          // 90.0
double angle = Math.toDegrees(Math.atan2(dy, dx));     // readable angle
double manual = radians * 180 / Math.PI;               // roughly the same
CallWhat it does
Math.toDegrees(Math.PI)A half turn: returns 180.0.
Math.toDegrees(Math.PI / 2)A quarter turn: returns 90.0.
Math.toDegrees(1.0)One radian: returns 57.29577951308232.
Math.toDegrees(Math.atan2(y, x))The direction of (x, y) in degrees, from -180 to 180.

There is only a double version. The method does not wrap angles into 0 to 360: Math.toDegrees(7.0) is about 401.07. Normalise afterwards with ((deg % 360) + 360) % 360.

Library declarations
Java
// java.lang.Math
public static double toDegrees(double angrad)

Parameters

ParameterDescription
angradAn angle measured in radians.

Return Value

Return ValueDescription
doubleThe same angle in degrees. NaN and infinities stay NaN or infinite, and the sign of a zero is kept.

Compare with Similar Methods

Converting and finding angles:

MethodHow it differs
toRadians(deg)The reverse conversion: degrees to radians.
rad * 180 / Math.PIThe hand-written version; may differ from toDegrees in the last digit.
atan2(y, x)A common source of the radians you convert.
acos(x)Another: returns radians from 0 to PI.

Java Examples

Example 1 — Radians to Degrees for the Familiar Angles

Convert the angles that come out exactly right under every Java version.

Java
public class MathToDegreesBasics {
    public static void main(String[] args) {
        System.out.println("toDegrees(0)        = " + Math.toDegrees(0));
        System.out.println("toDegrees(PI / 4)   = " + Math.toDegrees(Math.PI / 4));
        System.out.println("toDegrees(PI / 2)   = " + Math.toDegrees(Math.PI / 2));
        System.out.println("toDegrees(PI)       = " + Math.toDegrees(Math.PI));
        System.out.println("toDegrees(2 * PI)   = " + Math.toDegrees(2 * Math.PI));
        System.out.println("toDegrees(-PI)      = " + Math.toDegrees(-Math.PI));
        System.out.println("toDegrees(1.0)      = " + Math.toDegrees(1.0));
    }
}

How It Works

  1. Fractions of PI. A quarter, half, and whole PI map to 45, 90, and 180 degrees; each is a power-of-two fraction of PI, so the result comes out clean under every formula that Java versions use.
  2. Sign and size. A full turn is 360.0 and a negative angle stays negative (-180.0), because the conversion is only a multiplication.
  3. One radian. The number of degrees per radian is 180 / PI, about 57.29577951308232; this is the factor that the conversion applies to every input.

Example 2 — Why the Result Can Be 59.99999999999999

Some angles do not convert to a "round" number of degrees. Round them for display and compare with a tolerance.

Java
import java.util.Locale;

public class MathToDegreesRounding {
    public static void main(String[] args) {
        double sixty = Math.toDegrees(Math.PI / 3);
        double thirty = Math.toDegrees(Math.PI / 6);
        System.out.println("PI / 3 rounded: " + String.format(Locale.US, "%.2f", sixty));
        System.out.println("PI / 6 rounded: " + String.format(Locale.US, "%.2f", thirty));
        System.out.println("PI / 3 close to 60? " + (Math.abs(sixty - 60) < 1e-9));

        double angle = 1.2345;
        double back = Math.toRadians(Math.toDegrees(angle));
        System.out.println("round trip: " + String.format(Locale.US, "%.4f", back));
        System.out.println("round trip close? " + (Math.abs(back - angle) < 1e-12));
    }
}

How It Works

  1. PI / 3 is not exact. Math.PI / 3 is a rounded double, so the result may print as 59.99999999999999 or as 60.0 depending on the JDK; %.2f gives 60.00 in both cases.
  2. A tolerance test is portable. Whatever the last digit is, the distance from 60 is around 1E-14, so Math.abs(sixty - 60) < 1e-9 is true on every Java version.
  3. Round trip. Converting 1.2345 radians to degrees and back returns the same angle to well within 1e-12, so the pair of methods undo each other, up to a tiny rounding error.

Example 3 — Sensor Angles in Radians, Shown as Degrees and as a Dial Reading

A robot arm reports joint angles in radians. Convert them for the screen, and bring an angle that has gone past a full turn back to 0-360.

Java
import java.util.Locale;

public class MathToDegreesDial {
    public static void main(String[] args) {
        double[] joints = {0.5, 1.0, Math.PI / 2, 3.0};
        for (double rad : joints) {
            System.out.println(rad + " rad = " + String.format(Locale.US, "%.2f", Math.toDegrees(rad)) + " degrees");
        }

        double[] spins = {7.0, -1.0};
        for (double rad : spins) {
            double deg = Math.toDegrees(rad);
            double dial = ((deg % 360) + 360) % 360;
            System.out.println(rad + " rad = " + String.format(Locale.US, "%.2f", deg)
                    + " degrees = " + String.format(Locale.US, "%.2f", dial) + " on the dial");
        }
    }
}

How It Works

  1. About 57.3 per radian. Half a radian is 28.65 degrees and one radian is 57.30; the quarter turn Math.PI / 2 is 90.00, and 3.0 radians is almost a half turn.
  2. Beyond a full turn. 7.0 radians is 401.07 degrees, which is one full turn (360) plus 41.07, so % 360 leaves 41.07 on the dial.
  3. Negative angles need a second step. In Java -57.30 % 360 stays -57.30, so adding 360 and applying % 360 again gives 302.70, the positive angle for the same direction.

Frequently Asked Questions

It converts an angle from radians to degrees. Math.toDegrees(Math.PI) returns 180.0 and Math.toDegrees(Math.PI / 2) returns 90.0.
Math.PI / 3 is a rounded double, and the multiplication by 180 / PI rounds again. Depending on the JDK version the result is 59.99999999999999 or 60.0. Round for display or compare with a tolerance.
Wrap it: Math.toDegrees(Math.atan2(y, x)). The result runs from -180 to 180; use (deg + 360) % 360 to get 0 to 360.
Mathematically radians * 180 / PI. Older JDKs compute angrad * 180.0 / PI and newer ones multiply by a constant, so some results differ in the last digit.
Use Math.toRadians. Math.toRadians(180) returns Math.PI. It is the reverse of toDegrees.

Next: toIntExact()

Convert a long to an int and throw ArithmeticException if it does not fit.

toIntExact() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

15 people found this page helpful