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.3k Linux/Unix/PHP : Restart PHP-FPM
+34.6k Golang : Integer is between a range
+4.7k Golang : Check if a word is countable or not
+6.7k CloudFlare : Another way to get visitor's real IP address
+4.8k PHP : See installed compiled-in-modules
+5k Golang : Reclaim memory occupied by make() example
+7.7k Golang : How To Use Panic and Recover
+31.1k Golang : Convert an image file to []byte
+11.6k Linux : How to install driver for 600Mbps Dual Band Wifi USB Adapter
+5k Golang : Return multiple values from function
+8k Golang : How to check if input string is a word?
+8.1k Golang : Generate Datamatrix barcode