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
+16.7k Golang : Merge video(OpenCV) and audio(PortAudio) into a mp4 file
+8.1k Golang : Trim everything onward after a word
+43.8k Golang : Get hardware information such as disk, memory and CPU usage
+31.3k Golang : Calculate percentage change of two values
+6k Golang : Detect variable or constant type
+6.3k Golang : Get missing location after unmarshal binary and gob decode time.
+6.3k Golang : Scan forex opportunities by Bollinger bands
+26.6k Golang : Convert(cast) string to uint8 type and back to string
+16.6k Golang : Execute terminal command to remote machine example
+8k Golang : Reverse a string with unicode
+4.9k PHP : Extract part of a string starting from the middle
+8.6k Golang : Generate Datamatrix barcode