Home ยป How to Get Pi Value in Golang

How to Get Pi Value in Golang

To get Pi value in go:

  1. Import the math package in the golang program
  2. Use the Pi constant of the math package using math.pi
  3. It returns the Pi constant value as 3.14159

In this article, we will discuss how to get the pi constant value in golang with examples.

Get Pi Constant Value in Golang

Use the math.pi from the math package in golang to get pi constant value.

package main

import (
	"fmt"
	"math"
)

func main() {
	// Use the math.pi to get pi constant value
	pi := math.Pi

	// Print the maths pi constant value which is 3.14159
	fmt.Println(pi)
}

The output of the above Golang program to get the pi value in golang is:

3.141592653589793

Cool Tip: How to find the log of a number in golang!

Conclusion

I hope the above article helped you to get the pi value in golang using math.pi

You can find more topics about the Golang tutorials on the GolangSpot Home page.

Leave a Comment