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
+4.6k Golang : Byte format example
+6k Golang : Get uploaded file name or access uploaded files
+22.3k Golang : Convert []byte to image
+4.1k Golang : automatically figure out array length(size) with three dots
+3.4k Golang : Shuffle strings array
+2.3k Javascript : How to loop over and parse JSON data?
+2.4k Golang : Transform lisp or spinal case to Pascal case example
+9.6k Golang : Gzip file example
+2.5k Golang : Get missing location after unmarshal binary and gob decode time.
+8.7k Golang : Get IP addresses of a domain name
+4.6k Golang : How to determine a prime number?
+6.2k Golang: Pad right or print ending(suffix) zero or spaces in fmt.Printf example