Scala Tutorial Scala References

Scala - Math PI Field



The Scala Math Pi field is used to return the value of 𝜋 to the available precision. It returns the value of 𝜋 as 3.141592653589793.

Syntax

@inline final val Pi = java.lang.Math.PI

Parameters

No parameter is required.

Return Value

Returns the value of 𝜋 to the available precision.

Example:

In the example below, Pi constant is used to return the value of 𝜋 to the available precision.

import scala.math._

object MainObject {
  def main(args: Array[String]) {
    println(s"Pi = ${Pi}");   
    println(s"Area of the circle with radius 1.0 is: ${Pi*1*1}");
  }
}

The output of the above code will be:

Pi = 3.141592653589793
Area of the circle with radius 1.0 is: 3.141592653589793

❮ Scala Math Methods