Golang : Convert(cast) int64 to string
Problem :
You want to convert(cast) a big integer value to string for display.
Solution :
Use strconv.FormatInt() function to convert the int64 value to string. For example :
package main
import (
"fmt"
"strconv"
)
func main() {
var val int64 = 123456789
str := strconv.FormatInt(val, 10) // use base 10 for sanity purpose
fmt.Println(str) // int64 converted to string!
fmt.Printf("After conversion : %v \n", val) // alternate method works too!
}
Output :
123456789
After conversion : 123456789
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
+7.1k Android Studio : How to detect camera, activate and capture example
+5.8k Golang : Compound interest over time example
+20.8k Golang : How to force compile or remove object files first before rebuild?
+11.7k Golang : Detect user location with HTML5 geo-location
+25.7k Mac/Linux and Golang : Fix bind: address already in use error
+16.7k Golang : Get input from keyboard
+14.2k How to automatically restart your crashed Golang server
+6.6k How to let Facebook Login button redirect to a particular URL ?
+23.8k Golang : Find biggest/largest number in array
+18.3k Golang : Iterating Elements Over A List
+9k Golang : Generate random Chinese, Japanese, Korean and other runes