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
+4.7k Golang : How to detect if a sentence ends with a punctuation?
+5.6k Golang : Get YouTube playlist
+11.4k Golang : How to get URL port?
+10.5k Golang : Covert map/slice/array to JSON or XML format
+4.1k PHP : Proper way to get UTF-8 character or string length
+6.3k Swift : Convert (cast) String to Float
+10.1k Golang : Qt progress dialog example
+11.3k Golang : Google Drive API upload and rename example
+26k Golang : Get and Set User-Agent examples
+4.1k Javascript : How to refresh page with JQuery ?
+11.2k Golang : Fix cannot use buffer (type bytes.Buffer) as type io.Writer(Write method has pointer receiver) error