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.2k Golang : Test input string for unicode example
+19.5k Golang : Set or Add HTTP Request Headers
+8.6k Golang : Combine slices but preserve order example
+37.8k Golang : Read a text file and replace certain words
+11.3k Android Studio : Create custom icons for your application example
+8.7k Golang : Take screen shot of browser with JQuery example
+5.2k Golang : Get FX sentiment from website example
+21.9k Golang : Convert seconds to minutes and remainder seconds
+4.9k Golang : micron to centimeter example
+4.2k Golang : Converting individual Jawi alphabet to Rumi(Romanized) alphabet example
+8.6k Golang : Heap sort example
+7.7k Golang : Regular Expression find string example