One line answer is fmt.Sprint(i).

Anyway there are many conversions, even inside standard library function like fmt.Sprint(i), so you have some options (try The Go Playground):


1- You may write your conversion function (Fastest):

func String(n int32) string {
    buf := [11]byte{}
    pos := len(buf)
    i := int64(n)
    signed := i < 0
    if signed {
        i = -i
    }
    for {
        pos--
        buf[pos], i = '0'+byte(i%10), i/10
        if i == 0 {
            if signed {
                pos--
                buf[pos] = '-'
            }
            return string(buf[pos:])
        }
    }
}

2- You may use fmt.Sprint(i) (Slow)
See inside:

// Sprint formats using the default formats for its operands and returns the resulting string.
// Spaces are added between operands when neither is a string.
func Sprint(a ...interface{}) string {
    p := newPrinter()
    p.doPrint(a)
    s := string(p.buf)
    p.free()
    return s
}

3- You may use strconv.Itoa(int(i)) (Fast)
See inside:

// Itoa is shorthand for FormatInt(int64(i), 10).
func Itoa(i int) string {
    return FormatInt(int64(i), 10)
}

4- You may use strconv.FormatInt(int64(i), 10) (Faster)
See inside:

// FormatInt returns the string representation of i in the given base,
// for 2 <= base <= 36. The result uses the lower-case letters 'a' to 'z'
// for digit values >= 10.
func FormatInt(i int64, base int) string {
    _, s := formatBits(nil, uint64(i), base, i < 0, false)
    return s
}

Comparison & Benchmark (with 50000000 iterations):

s = String(i)                       takes:  5.5923198s
s = String2(i)                      takes:  5.5923199s
s = strconv.FormatInt(int64(i), 10) takes:  5.9133382s
s = strconv.Itoa(int(i))            takes:  5.9763418s
s = fmt.Sprint(i)                   takes: 13.5697761s

Code:

package main

import (
    "fmt"
    //"strconv"
    "time"
)

func main() {
    var s string
    i := int32(-2147483648)
    t := time.Now()
    for j := 0; j < 50000000; j++ {
        s = String(i) //5.5923198s
        //s = String2(i) //5.5923199s
        //s = strconv.FormatInt(int64(i), 10) // 5.9133382s
        //s = strconv.Itoa(int(i)) //5.9763418s
        //s = fmt.Sprint(i) // 13.5697761s
    }
    fmt.Println(time.Since(t))
    fmt.Println(s)
}

func String(n int32) string {
    buf := [11]byte{}
    pos := len(buf)
    i := int64(n)
    signed := i < 0
    if signed {
        i = -i
    }
    for {
        pos--
        buf[pos], i = '0'+byte(i%10), i/10
        if i == 0 {
            if signed {
                pos--
                buf[pos] = '-'
            }
            return string(buf[pos:])
        }
    }
}

func String2(n int32) string {
    buf := [11]byte{}
    pos := len(buf)
    i, q := int64(n), int64(0)
    signed := i < 0
    if signed {
        i = -i
    }
    for {
        pos--
        q = i / 10
        buf[pos], i = '0'+byte(i-10*q), q
        if i == 0 {
            if signed {
                pos--
                buf[pos] = '-'
            }
            return string(buf[pos:])
        }
    }
}
Answer from user6169399 on Stack Overflow
Top answer
1 of 5
119

One line answer is fmt.Sprint(i).

Anyway there are many conversions, even inside standard library function like fmt.Sprint(i), so you have some options (try The Go Playground):


1- You may write your conversion function (Fastest):

func String(n int32) string {
    buf := [11]byte{}
    pos := len(buf)
    i := int64(n)
    signed := i < 0
    if signed {
        i = -i
    }
    for {
        pos--
        buf[pos], i = '0'+byte(i%10), i/10
        if i == 0 {
            if signed {
                pos--
                buf[pos] = '-'
            }
            return string(buf[pos:])
        }
    }
}

2- You may use fmt.Sprint(i) (Slow)
See inside:

// Sprint formats using the default formats for its operands and returns the resulting string.
// Spaces are added between operands when neither is a string.
func Sprint(a ...interface{}) string {
    p := newPrinter()
    p.doPrint(a)
    s := string(p.buf)
    p.free()
    return s
}

3- You may use strconv.Itoa(int(i)) (Fast)
See inside:

// Itoa is shorthand for FormatInt(int64(i), 10).
func Itoa(i int) string {
    return FormatInt(int64(i), 10)
}

4- You may use strconv.FormatInt(int64(i), 10) (Faster)
See inside:

// FormatInt returns the string representation of i in the given base,
// for 2 <= base <= 36. The result uses the lower-case letters 'a' to 'z'
// for digit values >= 10.
func FormatInt(i int64, base int) string {
    _, s := formatBits(nil, uint64(i), base, i < 0, false)
    return s
}

Comparison & Benchmark (with 50000000 iterations):

s = String(i)                       takes:  5.5923198s
s = String2(i)                      takes:  5.5923199s
s = strconv.FormatInt(int64(i), 10) takes:  5.9133382s
s = strconv.Itoa(int(i))            takes:  5.9763418s
s = fmt.Sprint(i)                   takes: 13.5697761s

Code:

package main

import (
    "fmt"
    //"strconv"
    "time"
)

func main() {
    var s string
    i := int32(-2147483648)
    t := time.Now()
    for j := 0; j < 50000000; j++ {
        s = String(i) //5.5923198s
        //s = String2(i) //5.5923199s
        //s = strconv.FormatInt(int64(i), 10) // 5.9133382s
        //s = strconv.Itoa(int(i)) //5.9763418s
        //s = fmt.Sprint(i) // 13.5697761s
    }
    fmt.Println(time.Since(t))
    fmt.Println(s)
}

func String(n int32) string {
    buf := [11]byte{}
    pos := len(buf)
    i := int64(n)
    signed := i < 0
    if signed {
        i = -i
    }
    for {
        pos--
        buf[pos], i = '0'+byte(i%10), i/10
        if i == 0 {
            if signed {
                pos--
                buf[pos] = '-'
            }
            return string(buf[pos:])
        }
    }
}

func String2(n int32) string {
    buf := [11]byte{}
    pos := len(buf)
    i, q := int64(n), int64(0)
    signed := i < 0
    if signed {
        i = -i
    }
    for {
        pos--
        q = i / 10
        buf[pos], i = '0'+byte(i-10*q), q
        if i == 0 {
            if signed {
                pos--
                buf[pos] = '-'
            }
            return string(buf[pos:])
        }
    }
}
2 of 5
14

The Sprint function converts a given value to string.

package main

import (
     "fmt"
)

func main() {

      var sampleInt int32 = 1

      sampleString := fmt.Sprint(sampleInt)
      fmt.Printf("%+V %+V\n", sampleInt, sampleString)
}

// %!V(int32=+1) %!V(string=1)

See this example.

Discussions

go - Parse string to specific type of int (int8, int16, int32, int64) - Stack Overflow
I am trying to parse a string into an integer in Go. The Problem I found with it is in the documentation its mentioned syntax is as follows: ParseInt(s string, base int, bitSize int) where, s is the More on stackoverflow.com
🌐 stackoverflow.com
Which is the best way to convert int to string in golang ?
  1. is plain wrong

  2. is the most lightweight (in terms of dependency and performance)

  3. is the most flexible

More on reddit.com
🌐 r/golang
7
6
July 3, 2020
How to convert an int value to string in Go? - Stack Overflow
If you need to convert an int value to string, you can use faiNumber package. faiNumber is the fastest golang string parser library. All of faiNumber's function was benchmark to run way faster than the strconv package. faiNumber supports converting an int32, uint32, int64, or uint64 value to ... More on stackoverflow.com
🌐 stackoverflow.com
Convert uint32 to int in Go - Stack Overflow
Communities for your favorite technologies. Explore all Collectives · Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work More on stackoverflow.com
🌐 stackoverflow.com
🌐
Go Packages
pkg.go.dev › strconv
strconv package - strconv - Go Packages
i := int32(i64) FormatBool, FormatFloat, FormatInt, and FormatUint convert values to strings:
🌐
ByteSizeGo
bytesizego.com › blog › convert-int-to-string-golang
How to convert an int to string in Golang
September 10, 2024 - Update: This blog is also available as a lesson you can watch for free · The most straightforward and commonly used way to convert an integer to a string in Go is by using the strconv.Itoa() function.
🌐
YourBasic
yourbasic.org › golang › convert-int-to-string
Convert between int, int64 and string · YourBasic Go
The fmt.Sprintf function is a useful general tool for converting data to string: s := fmt.Sprintf("%+8d", 97) // s == " +97" (width 8, right justify, always show sign) See this fmt cheat sheet for more about formatting integers and other types of data with the fmt package. Package strconv · golang.org · Pick the right one: int vs. int64 · An index, length or capacity should normally be an int. The types int8, int16, int32, and int64 are best suited for data.
🌐
gosamples
gosamples.dev › tutorials › convert int to string in go
🔢 Convert int to string in Go
July 23, 2021 - 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) var number int64 = 12 // you can use any integer here: int, int32, int16, int8 str := strconv.FormatInt(number, 16) fmt.Println(str)
🌐
Golang.cafe
golang.cafe › blog › golang-int-to-string-conversion-example
Golang Int To String Conversion Example | Golang.cafe
April 27, 2022 - Go (Golang) provides string and integer conversion directly from a package coming from the standard library - strconv. In order to convert an integer value to string in Golang we can use the FormatInt function from the strconv package.
Find elsewhere
🌐
ZetCode
zetcode.com › golang › inttostring
Go int to string conversion
Learn how to convert integers to strings in Go. Includes examples of type conversion.
🌐
Boldly Go
boldlygo.tech › archive › 2024-03-13-converting-integers-to-strings
Converting integers to strings - Boldly Go
March 13, 2024 - Sorry I missed yesterday. The family road trip ended later than expected, and I was too shot to write anything. Conversions to and from a string type … Finally, for historical reasons, an integer value may be converted to a string type. This form of conversion yields a string containing the (possibly multi-byte) UTF-8 representation of the Unicode code point with the given integer value.
🌐
DEV Community
dev.to › divshekhar › convert-int-to-string-in-golang-itoa-and-formatint-710
Convert Int To String in Golang | Itoa and FormatInt - DEV Community
September 27, 2020 - In Order to Convert it into string, the rune type to be type casted to string. ... Lets see how the conversion from Golang Int to String works when we use the plain conversion as above:
🌐
Educative
educative.io › answers › how-to-convert-an-int-to-a-string-in-golang
How to convert an int to a string in Golang
An integer can be converted to a string in Golang using the Itoa function within the strconv library.
🌐
Medium
medium.com › @kode-n-rolla › type-conversion-in-go-a-handy-cheat-sheet-for-developers-51482d4dca0c
Type Conversion in Go: A Handy Cheat Sheet for Developers | by k0de-n-Яolla | Medium
February 27, 2026 - Working with Runes - Rune to String - Rune to Integer (int32) - Rune to Float (float64) - String to Runes - Runes to String - Extracting Digits from a String (with methods)
🌐
Hyno
hyno.co › blog › converting-an-integer-to-a-string-in-golang-a-comprehensive-guide.html
How to Convert an Integer to a String in Golang
The strconv package in Golang offers a convenient function called Itoa(). It converts an integer to its corresponding string representation.