To golang convert int to string, use the strconv package first: strconv.Itoa for int, or strconv.FormatInt(int64(n), base) for other bases. fmt.Sprintf("%d", n) is readable for mixed formatting. fmt.Fprintf writes the same representation to an io.Writer such as bytes.Buffer. For broader conversion rules, see type casting in Go.
Tested with Go 1.24 on Linux.
strconv.Itoa and strconv.FormatInt
package main
import (
"fmt"
"strconv"
)
func main() {
n := 42
fmt.Println(strconv.Itoa(n))
fmt.Println(strconv.FormatInt(int64(n), 16))
}You should see 42 then 2a.
fmt.Sprintf
package main
import "fmt"
func main() {
fmt.Println(fmt.Sprintf("%d", 42))
}fmt.Fprintf to a buffer
package main
import (
"bytes"
"fmt"
)
func main() {
var buf bytes.Buffer
fmt.Fprintf(&buf, "%d", 42)
fmt.Println(buf.String())
}strings.Builder (when assembling larger text)
For many fragments, strings.Builder avoids extra copies; for a single integer, strconv.Itoa remains simpler than hand-rolling digits unless you have special formatting needs.
Summary
Prefer strconv.Itoa / FormatInt for golang convert int to string in hot paths; use fmt.Sprintf or fmt.Fprintf when the integer is part of a larger formatted message. Avoid string(int) for decimal digits—it is not the same operation.

