Languages
[Edit]
EN

JavaScript - convert radians to degrees (rad to deg)

9 points
Created by:
Marcin
15680

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?
Native Advertising
50 000 ad impressions - 449$
šŸš€
Get your tech brand or product in front of software developers.
For more information contact us:
Red dot
Dirask - friendly IT community for everyone.

ā¤ļøšŸ’» šŸ™‚

Join