# How to convert Degrees to Radians in Swift?

Aug 09, 2022

When working with rotating view animations or 2d/3d games, you would have to eventually deal with degrees and radians at some point.

Even though, most people have a better understanding of degrees over radians, most of the angles are dealt in radians in Swift [and general math as a matter of fact].

Before diving into the coding path, let’s get the math part clear.

1 pi radian = 180 degrees

Note: pi = 3.14

Thus, for converting degrees to radians, you have to multiply it by pi and divide by 180.

`Radians = Degrees * π / 180`

## Computed Property Extension

One of the easy, clean and efficient way to convert degrees to radians is to extend a computed property to `BinaryFloatingPoint` which is basically a generic type which includes all the decimal numeric types - Float, Double.

``````extension BinaryFloatingPoint {
return self * .pi / 180
}
``````

Usage:

``````let degree : Float = 360 // 360 degrees
``````

## Extension Methods

Another convenient way of converting degrees to radians using a method over `BinaryFloatingPoint`, `Double` and `Float`.

``````extension BinaryFloatingPoint {
return self * .pi / 180
}
}
``````

Usage:

``````let degrees : Float = 360 // 360 degrees
``````// prints 6.283185 in console