Golang : Convert(cast) float to int
One of trait of a good programmer is laziness. There are times that I wish to have a complete source code for the project that I'm working on just by Googling for it. One of this is just simply ..... how to convert(cast) a float or float64 value to int type in Golang. :P
Without much further ado :
package main
import (
"fmt"
)
func main() {
var floatvalue float64 = 10.88
var intvalue int = int(floatvalue)
fmt.Println(intvalue)
// or
fmt.Println(int(floatvalue))
}
Output will be :
10
10
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
+8.4k Golang : Changing a RGBA image number of channels with OpenCV
+11.7k Golang : Drop cookie to visitor's browser and http.SetCookie() example
+4.3k Golang : Pad file extension automagically
+10.9k Golang : Convert a rune to unicode style string \u
+5.2k PageSpeed : Clear or flush cache on web server
+16.2k Golang : Multi threading or run two processes or more example
+29.9k Golang : Convert an image file to []byte
+18.4k Golang : Determine if directory is empty with os.File.Readdir() function
+35.7k Upload multiple files with Go
+13.8k nginx: [emerg] unknown directive "ssl"
+6.7k Setting $GOPATH environment variable for Unix/Linux and Windows
+40.3k Golang : Convert string to array/slice