Post

GoLangGoLang

n
naseer mohammad

Posted on 4th March 2024|133 views

0
votes

Golang Float To Int

How can I convert float type to integer in Golang?

Answers
P
Anthony A

Posted on 4th March 2024

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

 

Write your answer

STILL GOT QUERIES?

Get a Live FREE Demo
  • Explore the trending and niche courses and learning maps
  • Learn about tuition fee, payment plans, and scholarships
  • Get access to webinars and self-paced learning videos