Languages
[Edit]
EN

JavaScript - convert radians to degrees (rad to deg)

9 points
Created by:
Marcin
2447

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

Conversion can be made with following formula:

Simple implementaion is presented below.

1. Custom conversion method example

// ONLINE-RUNNER:browser;

function radToDeg(rad) {
    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

See also

  1. JavaScript - convert degrees to radians (deg to rad)

Merged questions

  1. How to make conversion from radians to degrees in JavaScript?
Hey 👋
Would you like to know what we do?
  • Dirask is a friendly IT community for learners, professionals and hobbyists to share their knowledge and help each other in extraordinary easy way.
  • We welcome everyone,
    no matter what the experience,
    no matter how basic the question is,
    this community will help you.