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
+9.7k PHP : Get coordinates latitude/longitude from string
+7.4k Golang : Convert source code to assembly language
+5.9k Facebook : How to force facebook to scrape latest URL link data?
+6.8k Golang : Get expvar(export variables) to work with multiplexer
+12.3k Golang : Validate email address
+13.8k Golang : Convert spaces to tabs and back to spaces example
+9.7k Golang : Load ASN1 encoded DSA public key PEM file example
+14.5k Golang : How to check if your program is running in a terminal
+7.1k Golang : Get Alexa ranking data example
+12.6k Golang : Sort and reverse sort a slice of bytes
+87.7k Golang : How to convert character to ASCII and back