Java - Math toDegrees(double x) 方法



描述

Java Math toDegrees(double angrad) 方法將以弧度表示的角度轉換為近似等價的以度表示的角度。從弧度到度的轉換通常是不精確的;使用者不應期望 cos(toRadians(90.0)) 完全等於 0.0。

宣告

以下是 java.lang.Math.toDegrees() 方法的宣告

public static double toDegrees(double angrad)

引數

angrad − 以弧度表示的角度

返回值

此方法返回以度表示的角度 angrad 的度量。

異常

從正雙精度值獲取角度示例

以下示例演示了對正雙精度值使用 Math toDegrees() 方法。

package com.tutorialspoint;

public class MathDemo {

   public static void main(String[] args) {

      // get a double number
      double x = 45.0;

      // print the degree for this double
      System.out.println("Math.toDegrees(" + x + ")=" + Math.toDegrees(x));
   }
}

輸出

讓我們編譯並執行以上程式,這將產生以下結果:

Math.toDegrees(45.0)=2578.3100780887044

從負雙精度值獲取角度示例

以下示例演示瞭如何使用 Math toDegrees() 方法獲取負雙精度值的度數。

package com.tutorialspoint;

public class MathDemo {

   public static void main(String[] args) {

      // get a double number
      double x = -45.0;

      // print the degree for this double
      System.out.println("Math.toDegrees(" + x + ")=" + Math.toDegrees(x));
   }
}

輸出

讓我們編譯並執行以上程式,這將產生以下結果:

Math.toDegrees(-45.0)=-2578.3100780887044

從零雙精度值獲取角度示例

以下示例演示瞭如何使用 Math toDegrees() 方法獲取零雙精度值的度數。

package com.tutorialspoint;

public class MathDemo {

   public static void main(String[] args) {

      // get a double number
      double x = 0.0;

      // print the degree for this double
      System.out.println("Math.toDegrees(" + x + ")=" + Math.toDegrees(x));
   }
}

輸出

讓我們編譯並執行以上程式,這將產生以下結果:

Math.toDegrees(0.0)=0.0
java_lang_math.htm
廣告