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
+4k Google : Block or disable caching of your website content
+14.4k Golang : Loop each day of the current month example
+12.7k Golang : How to convert a number to words
+6k Golang : Get Alexa ranking data example
+17.9k Golang : Clearing slice
+18k Golang : How to run your code only once with sync.Once object
+5.2k Golang : Build new URL for named or registered route with Gorilla webtoolkit example
+8.8k Golang : Check a web page existence with HEAD request example
+6.9k Golang : Get all countries phone codes
+16.2k Golang : How to remove certain lines from a file
+21.5k Golang : Get ASCII code from a key press(cross-platform) example