HiveBrain v1.2.0
Get Started
← Back to all entries
snippetgoCritical

Convert an integer to a float number

Submitted by: @import:stackoverflow-api··
0
Viewed 0 times
convertnumberintegerfloat

Problem

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?

Solution

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)
}

Code Snippets

package main

import "fmt"

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

Context

Stack Overflow Q#19230191, score: 234

Revisions (0)

No revisions yet.