Top community members
All Wiki Articles Create Wiki Article

Welcome to Dirask IT community! ā¤ šŸ’»
We are community that shares solutions with each other.

If you think you have something to add here.

you are welcome with your fresh ideas - List Articles

JavaScript - convert radians to degrees (rad to deg)

0 contributions
9 points

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?
0 contributions

Checkout latest Findings & News:

Checkout latest questions:

Checkout latest wiki articles:

Hey šŸ‘‹
Would you like to know what we do?
  • Dirask is IT community, where we share coding knowledge and help each other to solve coding problems.
  • We welcome everyone,
    no matter what the experience,
    no matter how basic the question is,
    this community will help you.
Read more