To convert an integer to a string in Golang, you can use the strconv.Itoa()
function. Here's an example:
package main
import (
"fmt"
"strconv"
)
func main() {
num := 42 // Integer
str := strconv.Itoa(num) // Convert integer to string
fmt.Printf("Integer: %d, String: %s\n", num, str)
}
In the above code, we declare an integer num
with the value of 42
. We then use strconv.Itoa()
to convert the integer num
to a string str
. The str
variable will now hold the string representation of the integer.
Finally, we print both the original integer num
and the converted string str
using fmt.Printf()
.