Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

int
string
conversion
go
golang

How to convert an int to a string in Golang

Educative Answers Team

An integer can be converted to a string in Golang using the Itoa function within the strconv library. This library supports conversions to and from string representations to various other data types.

The code snippet below shows how to convert an int to a string using the Itoa function.

package main
import "fmt"
import "strconv"
import "reflect" // The reflect library is used to obtain the datatype of an object.

func main() {
  num1:= 10
  fmt.Println(num1, reflect.TypeOf(num1))
  str:= strconv.Itoa(num1)
  fmt.Println(str, reflect.TypeOf(str))
}

RELATED TAGS

int
string
conversion
go
golang
Copyright ©2022 Educative, Inc. All rights reserved
RELATED COURSES

View all Courses

Keep Exploring