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
+12k Golang : Search and extract certain XML data example
+26.6k Golang : Find files by name - cross platform example
+7.2k Golang : Set horizontal, vertical scroll bars policies and disable interaction on Qt image
+24.5k Golang : Create PDF file from HTML file
+14.2k Golang : Convert(cast) int to float example
+9.7k CodeIgniter : Load different view for mobile devices
+15k Golang : Delete certain files in a directory
+20.9k Golang : How to read float value from standard input ?
+11.6k Golang : Sort and reverse sort a slice of runes
+5.1k Golang : If else example and common mistake
+13.7k Javascript : Prompt confirmation before exit
+13.8k Elastic Search : Mapping date format and sort by date