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
+10.2k Golang : Resolve domain name to IP4 and IP6 addresses.
+9.3k Golang : interface - when and where to use examples
+15.1k Golang : Intercept Ctrl-C interrupt or kill signal and determine the signal type
+27.6k Golang : Move file to another directory
+7.5k Golang : Handle Palindrome string with case sensitivity and unicode
+31k Golang : Example for ECDSA(Elliptic Curve Digital Signature Algorithm) package functions
+8.1k Golang : How to check variable or object type during runtime?
+8.9k Golang : Play .WAV file from command line
+4.5k HTTP common errors and their meaning explained
+45.4k Golang : Read tab delimited file with encoding/csv package
+30.6k Golang : bufio.NewReader.ReadLine to read file line by line
+5.6k Golang : Generate multiplication table from an integer example