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
+16.6k Golang : Gzip file example
+43.1k Golang : Get hardware information such as disk, memory and CPU usage
+12.4k Golang : Exit, terminating or aborting a program
+16.7k Golang : read gzipped http response
+5.9k Javascript : Get operating system and browser information
+10k Golang : How to tokenize source code with text/scanner package?
+11.8k Golang : Setup API server or gateway with Caddy and http.ListenAndServe() function example
+7.7k Golang : Load DSA public key from file example
+12.5k Golang : Drop cookie to visitor's browser and http.SetCookie() example
+23.4k Golang : Check if element exist in map
+30.1k Golang : How to verify uploaded file is image or allowed file types