Use strconv.FormatInt
operate to transform an integer variable to a string in Go.
int64 to a decimal string
var quantity int64 = 12
str := strconv.FormatInt(quantity, 10)
fmt.Println(str)
int, int32, int16, int8 to a decimal string
var quantity int = 12 // you should use any integer right here: int32, int16, int8
str := strconv.FormatInt(int64(quantity), 10)
fmt.Println(str)
To transform
int
tostring
you too can usestrconv.Itoa
which is equal tostrconv.FormatInt(int64(i), 10)
.quantity := 12 str := strconv.Itoa(quantity) fmt.Println(str)
int64 to a hexadecimal string
var quantity int64 = 12 // you should use any integer right here: int, int32, int16, int8
str := strconv.FormatInt(quantity, 16)
fmt.Println(str)
int64 to an octal string
var quantity int64 = 12 // int, int32, int16, int8
str := strconv.FormatInt(quantity, 8)
fmt.Println(str)
int64 to a binary string
var quantity int64 = 12 // int, int32, int16, int8
str := strconv.FormatInt(quantity, 2)
fmt.Println(str)