Nodejs Radian to Degree Convert toDeg()

Here you can find the source of toDeg()

Method Source Code

const degsInRad = 180 / Math.PI,
      radsInDeg = Math.PI / 180,//w  w w  .  ja  v a2 s. c  o m
      rad360 = Math.PI * 2;

Number.prototype.toDeg = function() {
    let deg = (this * degsInRad) % 360;
    if (deg < 0) {
        if (deg / 360 < -1) {
            deg += Math.floor((-deg) / 360) * 360
        } else {
            deg += 360;
        }
    }
    return deg;
}

Number.prototype.toRad = function() {
    let rad = (this * radsInDeg) % rad360;
    if (rad < 0) {
        if (rad / rad360 < -1) {
            rad += Math.floor((-rad) / rad360) * rad360
        } else {
            rad += rad360;
        }
    }
    return rad;
}

Related

  1. radToDeg(angle)
    function radToDeg(angle) {
      return ((angle * 180) / Math.PI);
    
  2. radToDeg(rad)
    function radToDeg(rad) {
      return rad / Math.PI * 180;
    
  3. toDegrees(radians)
    Math.toDegrees = function(radians) {
      return radians * 180 / Math.PI;
    };
    
  4. toDeg()
    Number.prototype.toDeg = function() {
      return this * 180 / Math.PI;
    Number.prototype.toRad = function() {
      return this * Math.PI / 180;
    
  5. toDeg()
    Number.prototype.toDeg = function() {
       return this * 180 / Math.PI;
    
  6. toDeg()
    Number.prototype.toDeg = function() {
      return (this * 180) / Math.PI;
    };
    
  7. toDeg() // convert radians to degrees (signed)
    Number.prototype.toDeg = function() {  
      return this * 180 / Math.PI;
    
  8. toDegrees()
    Number.prototype.toDegrees = function () {
        return this * (180 / Math.PI);
    };
    Number.prototype.toRadians = function () {
        return this * (Math.PI / 180);
    };
    Number.prototype.mod = function (n) {
        return ((this % n) + n) % n;
    };
    ...
    
  9. toDegrees()
    Number.prototype.toDegrees = function() { 
        return this.valueOf() * (180 * Math.PI);