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
+17.4k Golang : Example for RSA package functions
+7k Golang : Multiplexer with net/http and map
+18.3k Golang : Measure http.Get() execution time
+4k Javascript : How to get width and height of a div?
+13.1k Golang : Send email with attachment(RFC2822) using Gmail API example
+12.7k Golang : Fix image: unknown format error
+4.6k Golang : ROT32768 (rotate by 0x80) UTF-8 strings example
+11.1k Android Studio : Highlight ImageButton when pressed on example
+4.7k Golang : Grab news article text and use NLP to get each paragraph's sentences
+24.7k Golang : missing Mercurial command
+10.4k Golang : Secure file deletion with wipe example
+6.8k Javascript : Put image into Chrome browser's console