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.8k Golang : Convert(cast) io.Reader type to string
+5.7k PHP : Convert CSV to JSON with YQL example
+41.2k Golang : How to check if a string contains another sub-string?
+9.2k Golang : Build and compile multiple source files
+18.7k Golang : Generate thumbnails from images
+12.2k Golang : Perform sanity checks on filename example
+12.6k Golang : HTTP response JSON encoded data
+28.9k Golang : Detect (OS) Operating System
+10.2k Golang : Setting variable value with ldflags
+16.1k Golang : Update database with GORM example
+7.8k Javascript : Push notifications to browser with Push.js
+21.3k Golang : Convert(cast) string to rune and back to string example