Golang : Math pow(the power of x^y) example
No programming language will be complete without the power of
math function. This tutorial is a simple example on how to use math.Pow()
function.
In Math
2^5 = 2x2x2x2x2 =32
In Golang
Math.pow(2, 5)
In code :
package main
import (
"fmt"
"math"
)
func main() {
result := math.Pow(2, 5)
fmt.Println(" 2 power of 5 is : ", result)
x := 10.5
y := 5
floatResult := math.Pow(x, float64(y)) //type cast int to float64
fmt.Printf(" %.02f power of %d is : %.02f \n", x, y, floatResult)
}
2 power of 5 is : 32
10.50 power of 5 is : 127628.16
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+11.8k Golang : Pagination with go-paginator configuration example
+35.7k Golang : Converting a negative number to positive number
+8.6k Golang : Populate or initialize struct with values example
+8.5k Golang : Accept any number of function arguments with three dots(...)
+10.8k Google Maps URL parameters configuration
+7.6k Swift : Convert (cast) String to Double
+41.1k Golang : Convert string to array/slice
+5.9k Golang : Get Hokkien(福建话)/Min-nan(閩南語) Pronounciations
+13.4k Golang : Convert spaces to tabs and back to spaces example
+31.1k Golang : How to convert(cast) string to IP address?
+32k Golang : Copy directory - including sub-directories and files
+18.1k Golang : Get download file size