Convert an integer to a float number

go
user2671513 picture user2671513 · Oct 7, 2013 · Viewed 141.1k times · Source

How do I convert an integer value to float64 type?

I tried

float(integer_value)

But this does not work. And can't find any package that does this on Golang.org

How do I get float64 values from integer values?

Answer

zmb picture zmb · Oct 7, 2013

There is no float type. Looks like you want float64. You could also use float32 if you only need a single-precision floating point value.

package main

import "fmt"

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