Thursday 27 September 2018

go - Convert an integer to a float number in Golang



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



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


No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...