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
+5.3k Golang : Configure crontab to poll every two minutes 8am to 6pm Monday to Friday
+4.7k Golang : Display packages names during compilation
+3.8k Javascript : Empty an array example
+27.3k Golang : Decode/unmarshal unknown JSON data type with map[string]interface
+7.5k Golang : Regular Expression find string example
+11.2k Golang : Display a text file line by line with line number example
+4.9k Responsive Google Adsense
+5.6k Linux/MacOSX : Search for files by filename and extension with find command
+9.6k Golang : Detect number of faces or vehicles in a photo
+15k Golang : rune literal not terminated error
+13.5k Golang : Fix image: unknown format error
+14.9k Golang : invalid character ',' looking for beginning of value