In Golang, the data types are bound to variables rather than the values, which means that, if you declare a variable as int, then you can store only integer type value in it, you cant assign character or string in it unless you convert the data type to required data type.
To convert an integer data type to float you can wrap the integer with float64() or float32.
x = 5 y = 5.000000 y upto 3 decimal = 5.000 float64
Explanation: Firstly we declare a variable x of type int64 with a value of 5. Then we wrap x with float64(), which converts the integer 5 to float value of 5.00. The %.3f formats the float value upto 3 decimal points.
- How to Convert string to float type in Golang?
- Difference between const int*, const int * const, and int const *
- Converting a string variable into Boolean, Integer or Float type in Golang
- Golang | Searching an element of int type in slice of ints
- How to Get Int Type Random Number in Golang?
- Type Casting or Type Conversion in Golang
- How to Convert string to integer type in Golang?
- Different Ways to Convert the Boolean Type in String in Golang
- Finding Complementary Error Function of Float in Golang
- reflect.Float() Function in Golang with Examples
- reflect.Int() Function in Golang with Examples
- Difference between data type and data structure
- How to add a method to struct type in Golang?
- Searching an element of float64 type in Golang slice
- Searching an element of string type in Golang slice
- Type Switches in GoLang
- How to Get Float64 Type Random Number in Golang?
- How to Get Float32 Type Random Number in Golang?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.