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
+4.6k Golang : Get S3 or CloudFront object or file information
+8.8k Golang : Check if user agent is a robot or crawler example
+25.9k PHP : Count number of JSON items/objects
+16.2k Golang : How to remove certain lines from a file
+4.8k List of Golang XML tutorials
+7.6k Golang : How to find out similarity between two strings with Jaro-Winkler Distance?
+7k Golang : Qt splash screen with delay example
+9.3k Golang : Allow Cross-Origin Resource Sharing request
+2.7k Java : Get FX sentiment from website example
+8.6k Golang : Resumable upload to Google Drive(RESTful) example
+8.1k Golang : Timeout example
+6.8k Golang : get the current working directory of a running program