Languages
[Edit]
EN

TypeScript - convert degrees to radians (deg to rad)

0 points
Created by:
Dollie-Rutledge
806

In this article, we're going to have a look at how to convert degrees to radians using TypeScript. In TypeScript, there is no built-in conversion method. It is necessary to write your own one.

Conversion can be made with the following formula:

A simple implementation is presented below.

1. Custom conversion method example

const degToRad = (deg: number): number => {
  return deg * (Math.PI / 180.0);
};

// Usage example:

console.log(degToRad(0.0));   // 0                                 0.0 radians
console.log(degToRad(90.0));  // 1.5707963267948966       ~Math.PI / 2 radians
console.log(degToRad(180.0)); // 3.141592653589793            ~Math.PI radians

console.log(degToRad(30));  // 0.5235987755982988       ~Math.PI / 6 radians
console.log(degToRad(45));  // 0.7853981633974483       ~Math.PI / 4 radians
console.log(degToRad(90));  // 1.5707963267948966       ~Math.PI / 2 radians
console.log(degToRad(180)); // 3.141592653589793            ~Math.PI radians
console.log(degToRad(270)); // 4.71238898038469     ~3 * Math.PI / 2 radians
console.log(degToRad(360)); // 6.283185307179586        ~2 * Math.PI radians

Output:

0
1.5707963267948966
3.141592653589793

0.5235987755982988
0.7853981633974483
1.5707963267948966
3.141592653589793
4.71238898038469
6.283185307179586

Alternative titles

  1. How to make conversion from radians to degrees in TypeScript?
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join