Golang Code

Converting an Int to a String

· 71 words · 1 minute read #strconv #converting #int #string #fmt

This is a short example on how to convert an integer number into a string. This is a common use case when printing to screen or working with the number as if it was a string. To do this we use the strconv package and the Itoa function.

package main

import (
    "fmt"
    "strconv"
)

func main() {
    // Will print Number: 1234
    anInt := 1234
    fmt.Println("Number: " + strconv.Itoa(anInt))
}
Image of Author Edd Turtle

Author: Edd Turtle

Edd is the Lead Developer at Hoowla, a prop-tech startup, where he spends much of his time working on production-ready Go and PHP code.

See something which isn't right? You can contribute to this page on GitHub or just let us know in the comments below. Thanks for reading!