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
+6.4k Golang : Rename part of filename
+44.1k Golang : Read tab delimited file with encoding/csv package
+5.3k Golang : Break string into a slice of characters example
+15.2k Golang : Send email and SMTP configuration example
+5.1k Golang : Debug with Godebug
+8.1k Golang : Detect number of active displays and the display's resolution
+10.7k Golang : Detect user location with HTML5 geo-location
+8.4k Golang : Get all countries currencies code in JSON format
+15.9k Golang : Check if IP address is version 4 or 6
+10.3k Golang : Secure file deletion with wipe example
+25.1k Golang : Calculate future date with time.Add() function
+3.8k Python : Find out the variable type and determine the type with simple test