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
+3.9k MariaDB/MySQL : Form select statement or search query with Chinese characters
+8.4k Golang : Format strings to SEO friendly URL example
+13.9k Golang : rune literal not terminated error
+9.2k Golang : How to get quoted string into another string?
+5.9k Golang : Null and nil value
+10.9k Android Studio : Highlight ImageButton when pressed on example
+7.3k Golang : On lambda, anonymous, inline functions and function literals
+6.3k Golang : Hue, Saturation and Value(HSV) with OpenCV example
+3.9k Google : Block or disable caching of your website content
+12.9k Golang : Send email with attachment(RFC2822) using Gmail API example
+5.9k Golang : How to call function inside template with template.FuncMap