Languages
[Edit]
EN

JavaScript - convert radians to degrees (rad to deg)

12 points
Created by:
Blythe-F
650

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 the following formula:

A simple implementation is presented in the below.

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?
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.

JavaScript conversion

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