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
+6.1k Golang : Squaring elements in array
+14.4k Golang : How to convert(cast) IP address to string?
+16.2k Golang : Iterate linked list example
+5.9k Golang : Decode XML data from RSS feed
+10.4k Golang : Generate DSA private, public key and PEM files example
+14.2k Golang : Delete certain files in a directory
+10.5k How to tell if a binary(executable) file or web application is built with Golang?
+32.4k Golang : All update packages with go get command
+4.8k Unix/Linux : Get reboot history or check when was the last reboot date
+4.8k Golang : Markov chains to predict probability of next state example
+30k Golang : Example for ECDSA(Elliptic Curve Digital Signature Algorithm) package functions