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
+8.9k Golang : Convert octal value to string to deal with leading zero problem
+38.8k Golang : How do I convert int to uint8?
+7k Golang : Tell color name with OpenCV example
+32.3k Golang : All update packages with go get command
+12.5k Golang : Tutorial on loading GOB and PEM files
+4.9k PHP : How to handle URI or URL with non-ASCII characters such as Chinese/Japanese/Korean(CJK) ?
+23.7k Golang : Storing cookies in http.CookieJar example
+33.8k Golang : Save image to PNG, JPEG or GIF format.
+18.2k Golang : Compare floating-point numbers
+15.1k Golang :Trim white spaces from a string
+12.4k Golang : How to get year, month and day?