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 : Go as a script or running go with shebang/hashbang style
+12.4k Golang : Display list of countries and ISO codes
+30.6k Golang : Generate random string
+15.4k Golang : Get query string value on a POST request
+17.2k Golang : Capture stdout of a child process and act according to the result
+11.1k How to test Facebook App on localhost ?
+6k Golang : Use NLP to get sentences for each paragraph example
+7.8k Golang : Convert(cast) io.Reader type to string
+29.2k Golang : Get first few and last few characters from string
+25.8k Golang : missing Mercurial command
+15.4k JavaScript/JQuery : Detect or intercept enter key pressed example
+7.6k Golang : Get YouTube playlist