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
+7.5k Linux : How to fix Brother HL-1110 printing blank page problem
+11k Golang : How to transmit update file to client by HTTP request example
+21.9k SSL : How to check if current certificate is sha1 or sha2
+19.3k Golang : Populate dropdown with html/template example
+19.8k Golang : Archive directory with tar and gzip
+6k Golang : Shuffle array of list
+7.8k Golang : Scan files for certain pattern and rename part of the files
+31.8k Golang : How to convert(cast) string to IP address?
+27.7k Golang : dial tcp: too many colons in address
+7.6k SSL : How to check if current certificate is sha1 or sha2 from command line
+9.8k Golang : Qt get screen resolution and display on center example
+25.3k Golang : Storing cookies in http.CookieJar example