Scala Tutorial Scala References

Scala - Math toDegrees() Method



The Scala Math toDegrees() method returns an angle measured in radians to an approx. equivalent angle measured in degrees.

Syntax

def toDegrees(x: Double): Double = java.lang.Math.toDegrees(x)

Parameters

x Specify an angle in radians.

Return Value

Returns the angle measured in degrees.

Exception

NA.

Example:

In the example below, toDegrees() method returns an angle measured in radians into angle measured in degrees.

import scala.math._

object MainObject {
  def main(args: Array[String]) {
    println(s"toDegrees(Pi/6) = ${toDegrees(Pi/6)}");
    println(s"toDegrees(Pi/3) = ${toDegrees(Pi/3)}");
    println(s"toDegrees(Pi/2) = ${toDegrees(Pi/2)}");
    println(s"toDegrees(Pi) = ${toDegrees(Pi)}");
    println(s"toDegrees(2*Pi) = ${toDegrees(2*Pi)}"); 
  }
}

The output of the above code will be:

toDegrees(Pi/6) = 29.999999999999996
toDegrees(Pi/3) = 59.99999999999999
toDegrees(Pi/2) = 90.0
toDegrees(Pi) = 180.0
toDegrees(2*Pi) = 360.0

❮ Scala - Math Methods