Top community members
All Wiki Articles Create Wiki Article

Have you ever heard about encyclopedia for code?

What about: Wiki for Code project?

* because I've tried to share code and my solutions on different services and it was removed or I was unwelcomed
   - maybe it wasn't good place, but this one is.

if you think you have solution that can help someone, you are welcome to share this solution - Click here

JavaScript - convert degrees to radians (deg to rad)

0 contributions
4 points

In this article, we're going to have a look at how to convertĀ degrees toĀ radians 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 degToRad(deg) {
    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

See also

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

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