Cookies management by TermsFeed Cookie Consent
Russia has invaded Ukraine and already killed tens of thousands of civilians, with many more raped or tortured. It's a genocide. We need your help. Let's fight back against the Russian regime.
Help Ukraine! Fight the Russian regime!

πŸ”’ Convert int to string in Go

introduction numbers integer

Please consider supporting us by disabling your ad blocker

Use strconv.FormatInt function to convert an integer variable to a string in Go.

int64 to a decimal string

var number int64 = 12
str := strconv.FormatInt(number, 10)
fmt.Println(str)

int, int32, int16, int8 to a decimal string

var number int = 12 // you can use any integer here: int32, int16, int8
str := strconv.FormatInt(int64(number), 10)
fmt.Println(str)

To convert int to string you can also use strconv.Itoa which is equivalent to strconv.FormatInt(int64(i), 10).

number := 12
str := strconv.Itoa(number)
fmt.Println(str)

int64 to a hexadecimal string

var number int64 = 12 // you can use any integer here: int, int32, int16, int8
str := strconv.FormatInt(number, 16)
fmt.Println(str)

int64 to an octal string

var number int64 = 12 // int, int32, int16, int8
str := strconv.FormatInt(number, 8)
fmt.Println(str)

int64 to a binary string

var number int64 = 12 // int, int32, int16, int8
str := strconv.FormatInt(number, 2)
fmt.Println(str)

🎠 Round float to any precision in Go

Learn how to create a universal rounding function
introduction numbers math

♾️ Infinite loop in Go

Learn how to define a "while true" loop
introduction loop

πŸ“” Convert a struct to io.Reader in Go

Learn how to convert a struct to io.Reader and send it as an HTTP POST request body
introduction http