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.1k Golang : cannot assign type int to value (type uint8) in range error
+3.8k Python : Find out the variable type and determine the type with simple test
+23.7k Golang : Storing cookies in http.CookieJar example
+5.6k Golang : Humanize and Titleize functions
+23.9k Golang : Convert uint value to string type
+10.8k Golang : Convert a rune to unicode style string \u
+4.9k Golang : How to search a list of records or data structures
+8.4k Golang : Accessing content anonymously with Tor
+10.6k Golang : Convert(cast) bigint to string
+9.3k Generate Random number with math/rand in Go
+13.1k Golang : How to determine if user agent is a mobile device example
+7.9k Golang : HTTP Routing with Goji example