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
+22.4k Generate checksum for a file in Go
+8.8k Golang : Gaussian blur on image and camera video feed examples
+5.2k PHP : Hide PHP version information from curl
+11.5k Golang : Calculations using complex numbers example
+10k Golang : Compare files modify date example
+12.5k Golang : Get absolute path to binary for os.Exec function with exec.LookPath
+15.6k Golang : How to login and logout with JWT example
+8.7k Android Studio : Image button and button example
+14.9k Golang : How do I get the local IP (non-loopback) address ?
+5.6k List of Golang XML tutorials
+12.3k Golang : "https://" not allowed in import path
+7.4k Golang : Shuffle strings array