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
+8.1k Golang : How to feed or take banana with Gorilla Web Toolkit Session package
+5.4k Golang : The Tao of importing package
+4.9k Fix Google Analytics Redundant Hostnames problem
+6.2k Fontello : How to load and use fonts?
+21.5k Golang : Clean up null characters from input data
+7.2k Golang : How to solve "too many .rsrc sections" error?
+13k Golang : Convert int(year) to time.Time type
+10k Golang : interface - when and where to use examples
+19.4k Golang : Delete item from slice based on index/key position
+21.7k Curl usage examples with Golang
+7.6k Golang : How to detect if a sentence ends with a punctuation?
+20.6k Golang : Check if os.Stdin input data is piped or from terminal