Home » Core Golang » Convert Integer to String in Golang

Convert Integer to String in Golang

To convert an int value to string in Golang we can use the strconv package’s Itoa function.

It is interesting to note that strconv.Itoa is shorthand for with base 10

func FormatInt(i int64, base int) string

For Example:

strconv.Itoa(123)

is equivalent to

strconv.FormatInt(int64(123), 10)

Below you can find whole example:

package main

import (
	"fmt"
	"strconv"
)

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

	formatInt := strconv.FormatInt(int64(123), 10)
	fmt.Println(formatInt)
}

akotako

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top