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.9k Golang : How to get quoted string into another string?
+33.5k Golang : convert(cast) bytes to string
+9.4k Golang : Find correlation coefficient example
+10.7k Golang : Create Temporary File
+7.4k Golang : Mapping Iban to Dunging alphabets
+6.1k Golang : Selection sort example
+10k Golang : How to check if a website is served via HTTPS
+14.2k Golang : How to filter a map's elements for faster lookup
+9.2k Mac OSX : Get a process/daemon status information
+6.4k Golang : Warp text string by number of characters or runes example
+4.4k MariaDB/MySQL : How to get version information
+9.9k Golang : Check a web page existence with HEAD request example