HiveBrain v1.2.0
Get Started
← Back to all entries
snippetgoCritical

How to convert an int value to string in Go?

Submitted by: @import:stackoverflow-api··
0
Viewed 0 times
howintconvertvaluestring

Problem

i := 123
s := string(i)


s is 'E', but what I want is "123"

Please tell me how can I get "123".

Solution

Use the strconv package's Itoa function.

For example:

package main

import (
    "strconv"
    "fmt"
)

func main() {
    t := strconv.Itoa(123)
    fmt.Println(t)
}

Code Snippets

package main

import (
    "strconv"
    "fmt"
)

func main() {
    t := strconv.Itoa(123)
    fmt.Println(t)
}

Context

Stack Overflow Q#10105935, score: 1284

Revisions (0)

No revisions yet.