Scala - Math toRadians() Method
The Scala Math toRadians() method returns an angle measured in degrees to an approx. equivalent angle measured in radians.
Syntax
def toRadians(x: Double): Double = java.lang.Math.toRadians(x)
Parameters
x |
Specify an angle in degrees. |
Return Value
Returns the angle measured in radians.
Exception
NA.
Example:
In the example below, toRadians() method returns an angle measured in degrees into angle measured in radians.
import scala.math._ object MainObject { def main(args: Array[String]) { println(s"toRadians(30) = ${toRadians(30)}"); println(s"toRadians(45) = ${toRadians(45)}"); println(s"toRadians(90) = ${toRadians(90)}"); println(s"toRadians(180) = ${toRadians(180)}"); println(s"toRadians(360) = ${toRadians(360)}"); } }
The output of the above code will be:
toRadians(30) = 0.5235987755982988 toRadians(45) = 0.7853981633974483 toRadians(90) = 1.5707963267948966 toRadians(180) = 3.141592653589793 toRadians(360) = 6.283185307179586
❮ Scala - Math Methods