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.4k Get form post value in Go
+39.7k Golang : How to check if a string contains another sub-string?
+14.9k Golang : Get IP addresses of a domain name
+28.6k Golang : How to get HTTP request header information?
+8.2k Golang : How to get garbage collection data?
+6k Golang : Fibonacci number generator examples
+10.8k Golang : Simple client-server HMAC authentication without SSL example
+8.9k Golang : Find and replace data in all files recursively
+15.4k Golang : File path independent of Operating System
+18k Golang : How to get own program name during runtime ?
+12.6k Golang : Fix image: unknown format error
+8.4k Golang : Launch Mac OS X Preview (or other OS) application from your program example