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
+6k Golang : How to iterate a slice without using for loop?
+8.4k Golang : Get all countries currencies code in JSON format
+17.3k Golang : Example for RSA package functions
+5.1k PageSpeed : Clear or flush cache on web server
+10.8k Golang : Simple client-server HMAC authentication without SSL example
+10.5k Golang : Find and draw contours with OpenCV example
+16.3k Google Chrome : Your connection to website is encrypted with obsolete cryptography
+13.5k Golang : Normalize unicode strings for comparison purpose
+8.2k Golang : How to control fmt or log print format?
+9.6k Golang : Replace a parameter's value inside a configuration file example
+11.6k Golang : Drop cookie to visitor's browser and http.SetCookie() example