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.1k Golang : Add build version and other information in executables
+10.2k Golang : Embed secret text string into binary(executable) file
+14.3k Golang : Recombine chunked files example
+19.2k Golang : Execute shell command
+6.6k Golang : Reverse by word
+8.9k Golang : automatically figure out array length(size) with three dots
+12.9k Swift : Convert (cast) Int to String ?
+11.5k Android Studio : Create custom icons for your application example
+14.1k Golang : Fix image: unknown format error
+34k Golang : Create x509 certificate, private and public keys
+8.7k Golang : Executing and evaluating nested loop in html template
+11.6k Golang : How to detect a server/machine network interface capabilities?