degrees
radians
angle conversion
mathematics
trigonometry

How can I convert from degrees to radians?

Data Structures & Algorithms practice on Codemia

Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.

Practice algorithms

Introduction

Converting degrees to radians is one of the most common angle conversions in math, graphics, and programming. The rule is simple: multiply the degree value by pi / 180.

That formula comes from the fact that a full circle is 360 degrees and also 2 * pi radians. Once you know that relationship, the conversion becomes mechanical and easy to code.

Start with the Core Formula

The conversion formula is:

radians = degrees * (pi / 180)

So:

  • '180 degrees becomes pi radians'
  • '90 degrees becomes pi / 2'
  • '45 degrees becomes pi / 4'

For example, converting 60 degrees:

60 * (pi / 180) = pi / 3

That is the exact symbolic answer. In code, you usually compute a floating-point approximation.

Convert in Code

In Python:

python
1import math
2
3degrees = 60
4radians = degrees * math.pi / 180
5
6print(radians)
7print(math.radians(degrees))

The second line uses Python's built-in helper, which is usually the clearest option when one exists.

In JavaScript:

javascript
1const degrees = 60;
2const radians = degrees * Math.PI / 180;
3
4console.log(radians);

In Swift:

swift
1import Foundation
2
3let degrees = 60.0
4let radians = degrees * .pi / 180.0
5
6print(radians)

These examples all use the same formula. Only the language syntax changes.

Know Why Radians Matter

Radians are not just another unit. They are the natural angle unit in many mathematical formulas. Calculus, trigonometric derivatives, and many graphics or physics APIs assume radians.

That is why code often converts to radians even when the input is easier for humans to think about in degrees.

For example:

  • game engines often use radians for rotation functions
  • trigonometric libraries expect radians
  • physics formulas for angular velocity are usually expressed in radians

So the conversion is often a boundary between user-facing input and computation-facing math.

It is also a good mental check when reading formulas. If a trigonometric identity or API documentation assumes radians, converting once at the input boundary is usually cleaner than sprinkling degree-to-radian conversions throughout the code.

Convert Back When Needed

The reverse formula is just as useful:

degrees = radians * (180 / pi)

In Python:

python
1import math
2
3radians = math.pi / 3
4degrees = radians * 180 / math.pi
5
6print(degrees)
7print(math.degrees(radians))

Knowing both directions helps when debugging code that mixes UI input, mathematical functions, and stored values.

Common Pitfalls

The biggest mistake is mixing up the fraction and multiplying by 180 / pi when you meant degrees-to-radians. That applies the reverse conversion and produces the wrong scale.

Another common issue is forgetting that most programming language trig functions expect radians. Passing degree values directly into sin, cos, or tan usually produces confusing results.

It is also easy to lose track of whether a value is symbolic or numeric. pi / 3 is exact as math notation, while the code version is a floating-point approximation.

Finally, keep the unit explicit in variable names or comments when the codebase mixes both degrees and radians. That prevents subtle bugs in geometry and graphics code.

Unit clarity saves debugging time.

Summary

  • Convert degrees to radians with degrees * (pi / 180).
  • Convert radians to degrees with radians * (180 / pi).
  • Use built-in helpers such as math.radians() when available.
  • Remember that many math and graphics APIs expect radians.
  • Keep angle units explicit so degree and radian values are not mixed accidentally.

Related reading
Course
Intermediate
27 lessons
15 hours
DSA Fundamentals

Master algorithmic patterns and data structures through hands-on LeetCode-style problems - from arrays and hashing to dynamic programming and advanced graphs.

View the course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

Data Structures & Algorithms practice on Codemia

Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.

Practice algorithms

All Rights Reserved.