OneBite.Dev - Coding blog in a bite size

convert variable from int to string in Go

Code snippet on how to convert variable from int to string in Go

  intNumber := 12
  stringNumber := strconv.Itoa(intNumber)

This code converts an integer value, such as 12, into a string value, such as “12”. The code starts by declaring intNumber as an integer value and assigning it the number 12. The second line of code uses the function strconv.Itoa() from the strconv package. This function takes in an integer value and returns a string value. As a result, the content of intNumber, which is 12, is passed in and converted to a string, which is then stored in the stringNumber variable.

go