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
+40.6k Golang : Convert []byte to image
+15.4k Golang : Set up source IP address before making HTTP request
+12.6k Golang : Compress and decompress file with compress/flate example
+5.2k Golang : Selection sort example
+15.1k Golang : Check if a string contains multiple sub-strings in []string?
+5.2k Golang : Join lines with certain suffix symbol example
+16.1k Golang : delete and modify XML file content
+3.7k Mac OSX : Get disk partitions' size, type and name
+9k Golang : Get escape characters \u form from unicode characters
+15.2k Golang : Convert slice to array
+4.4k PHP : Hide PHP version information from curl