Posted on 9th September 2024|138 views
How can I convert float type to integer in Golang?
Posted on 9th September 2024| views
We can convert float type to integer in Golang, but the program you are working on will lose the accuracy of the float. Here is the example of converting float type to integer.
Example:
var f float64 = 458.9
var i int = int(f)
fmt.printf(“f = %.2f\n”, f)
fmt.printf(“i = %d\n”, i)
Output:
f = 458.90
i = 458