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 CodeIgniter : Load different view for mobile devices
+3.8k Golang : How to pass data between controllers with JSON Web Token
+17.4k Golang : Generate thumbnails from images
+8.4k Golang : Changing a RGBA image number of channels with OpenCV
+17.1k Golang : Find IP address from string
+18.5k Golang : Check if os.Stdin input data is piped or from terminal
+3.9k Golang : A program that contain another program and executes it during run-time
+21k Golang : Read directory content with filepath.Walk()
+10.7k Golang : Convert(cast) float to int
+8.1k Golang : Inject/embed Javascript before sending out to browser example
+4k Fix Google Analytics Redundant Hostnames problem
+4.3k Gogland : Datasource explorer