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 Golang : Lock executable to a specific machine with unique hash of the machine
+18.8k Golang : Get host name or domain name from IP address
+10.8k Golang : Create S3 bucket with official aws-sdk-go package
+17.8k Golang : Check if a directory exist or not
+19.2k Golang : How to Set or Add Header http.ResponseWriter?
+16.8k Golang : How to tell if a file is compressed either gzip or zip ?
+3.9k Javascript : Empty an array example
+18.8k Golang : Populate dropdown with html/template example
+8.2k PHP : How to parse ElasticSearch JSON ?
+9.4k Golang : Sort and reverse sort a slice of floats
+13.3k Golang : Set image canvas or background to transparent
+11k Golang : Delay or limit HTTP requests example