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
+14k Golang : How to pass map to html template and access the map's elements
+18.1k Golang : Get path name to current directory or folder
+8.9k Golang : Simple histogram example
+31.5k Golang : Convert an image file to []byte
+7.2k Golang : Word limiter example
+6.5k Golang : Skip or discard items of non-interest when iterating example
+3.5k Java : Random alphabets, alpha-numeric or numbers only string generator
+4.8k Linux : How to set root password in Linux Mint
+6.8k Golang : Takes a plural word and makes it singular
+27.6k Golang : Decode/unmarshal unknown JSON data type with map[string]interface
+6.7k Get Facebook friends working in same company
+16.6k Golang : How to generate QR codes?