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
+5.4k Unix/Linux/MacOSx : How to remove an environment variable ?
+13.9k Golang : Gin framework accept query string by post request example
+7.7k Golang : How to execute code at certain day, hour and minute?
+37.7k Golang : Comparing date or timestamp
+4.6k JavaScript : Rounding number to decimal formats to display currency
+31.2k Golang : Calculate percentage change of two values
+10k Golang : Convert octal value to string to deal with leading zero problem
+11.4k Golang : How to flush a channel before the end of program?
+16.1k Golang : Get sub string example
+6.2k Golang : Get Hokkien(福建话)/Min-nan(閩南語) Pronounciations
+10k Golang : Translate language with language package example
+33.1k Delete a directory in Go