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
+8.1k Golang : How To Use Panic and Recover
+10.9k Golang : Natural string sorting example
+6.9k Mac/Linux/Windows : Get CPU information from command line
+10k Golang : Get escape characters \u form from unicode characters
+6.2k Golang : Get Hokkien(福建话)/Min-nan(閩南語) Pronounciations
+8.8k Golang : Heap sort example
+6.9k Mac OSX : Find large files by size
+6.5k Grep : How to grep for strings inside binary data
+8k Golang : Sort words with first uppercase letter
+17.7k Golang : delete and modify XML file content
+23.2k Golang : Print out struct values in string format
+20.1k Golang : How to run your code only once with sync.Once object