Cannot convert int to float . I tried in the following way:

 float(integer_value) 

But this method does not work. What is the problem?

  • Type float not in go. There are only float32 and float64 . - Ainar-G

1 answer 1

Use float64 or float32 .

Example ( playground ):

 package main import "fmt" func main() { i := 5 f := float64(i) fmt.Printf("f = %f\n", f) } 

float32 one decimal place precision.