logo-MindMajix
PostGoLangGoLang
n
naseer mohammad

Posted on 16th June 2024|138 views

0
votes

Golang Float To Int

How can I convert float type to integer in Golang?

1 answers
Answers
P
Anthony A

Posted on 16th June 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

 

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
Name
Course *
Email *
Phone Number