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
+51.7k Golang : Disable security check for HTTPS(SSL) with bad or expired certificate
+18.8k Golang : Find IP address from string
+8.9k Golang : Gorilla web tool kit schema example
+5.1k Google : Block or disable caching of your website content
+32k Golang : Get local IP and MAC address
+15.4k JavaScript/JQuery : Detect or intercept enter key pressed example
+12.3k Golang : convert(cast) string to integer value
+13.7k Golang : Read XML elements data with xml.CharData example
+10.7k RPM : error: db3 error(-30974) from dbenv->failchk: DB_RUNRECOVERY: Fatal error, run database recovery
+22.4k Golang : Securing password with salt
+4.8k JavaScript : Rounding number to decimal formats to display currency
+14.1k Golang : Get current time