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
+11.2k Android Studio : Create custom icons for your application example
+12.2k Golang : Search and extract certain XML data example
+25k Golang : Storing cookies in http.CookieJar example
+9.5k PHP : Get coordinates latitude/longitude from string
+5.3k Gogland : Datasource explorer
+8.8k Golang : Inject/embed Javascript before sending out to browser example
+9.1k Golang : How to get ECDSA curve and parameters data?
+6.7k Golang : Calculate BMI and risk category
+9.7k Golang : Check if user agent is a robot or crawler example
+9.5k Golang : Load ASN1 encoded DSA public key PEM file example
+11.1k Golang : How to flush a channel before the end of program?
+9.6k Golang : Turn string or text file into slice example