Home »
Golang »
Golang Reference
Golang math.E Constant with Examples
Golang | math.E Constant: Here, we are going to learn about the E constant of the math package with its usages, syntax, and examples.
Submitted by IncludeHelp, on August 24, 2021
math.E Constant
The E constant is an inbuilt constant of the math package which is used to get the value of mathematical constant e. The number e, also known as Euler's number, is a mathematical constant approximately equal to 2.71828.
Syntax
float64 math.E
Parameters
Return Value
The return type of math.E constant is float64, it returns the value of mathematical constant e.
Example 1
// Golang program to demonstrate the
// example of math.E Constant
package main
import (
"fmt"
"math"
)
func main() {
fmt.Printf("Type of math.E is %T\n", math.E)
fmt.Println("Value of math.E:", math.E)
}
Output:
Type of math.E is float64
Value of math.E: 2.718281828459045
Explanation:
In the above program, we imported the math package to use the math.E constant, then printed the type and value of the math.E constant.
Example 2
// Golang program to demonstrate the
// example of math.E Constant
package main
import (
"fmt"
"math"
)
// creating function to return
// the value of e.
func getE() float64 {
return math.E
}
func main() {
fmt.Println("Value of math.E:", getE())
}
Output:
Value of math.E: 2.718281828459045
Golang math Package Constants and Functions »