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
+10.7k Golang : Transform comma separated string to slice example
+7.4k Golang : How to control fmt or log print format?
+10k Golang : Handle API query by curl with Gorilla Queries example
+8k Golang : Sort and reverse sort a slice of floats
+15.2k Golang : How to save log messages to file?
+19.7k Golang : Fix type interface{} has no field or no methods and type assertions example
+3.8k Golang : Frobnicate or tweaking a string example
+6.8k Golang : Sort lines of text example
+43.2k Golang : Disable security check for HTTPS(SSL) with bad or expired certificate
+10k CodeIgniter : Import Linkedin data
+5.9k Golang : Convert(cast) io.Reader type to string
+14.3k Golang : Convert slice to array