Languages
[Edit]
EN

TypeScript - convert radians to degrees (rad to deg)

0 points
Created by:
Palus-Bear
1016

In this article, we're going to have a look at how to convert radians to degrees 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 radToDeg = (rad: number): number => {
  return rad * (180.0 / Math.PI);
};

// Usage example:
console.log(radToDeg(0));           //   0.0 degrees
console.log(radToDeg(Math.PI / 2)); //  90.0 degrees
console.log(radToDeg(Math.PI));     // 180.0 degrees

console.log(radToDeg(3.141592653589793 / 6));   // ~30 degrees
console.log(radToDeg(3.141592653589793 / 4));   //  45 degrees
console.log(radToDeg(3.141592653589793 / 2));   //  90 degrees
console.log(radToDeg(3.141592653589793));       // 180 degrees
console.log(radToDeg(3.141592653589793 * 1.5)); // 270 degrees
console.log(radToDeg(3.141592653589793 * 2));   // 360 degrees

Output:

0
90
180

29.999999999999996
45
90
180
270
360

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