In Go, you can convert an integer to a string using the strconv.Itoa()
function.
In this example,
strconv
package which contains the itoa()
function.num
and assign it a value of 42
.num
to a string using the strconv.Itoa()
function and store the result in the variable strNum
.strconv.Itoa()
function converts the integer to its string representation.// Convert Integer to String
package main
import (
"fmt"
"strconv"
)
func main() {
num := 42
strNum := strconv.Itoa(num)
fmt.Println("String representation of integer:", strNum)
}
String representation of integer: 42
In this example,
strconv
package which contains the itoa()
function.negativeNum
with a value of -10
.negativeNum
to a string using the strconv.Itoa()
function and store the result in the variable strNegativeNum
.strconv.Itoa()
function converts the integer to its string representation.// Convert Negative Integer to String
package main
import (
"fmt"
"strconv"
)
func main() {
negativeNum := -10
strNegativeNum := strconv.Itoa(negativeNum)
fmt.Println("String representation of negative integer:", strNegativeNum)
}
String representation of negative integer: -10
In this tutorial, we learned How to Convert Integer to String in Go language with well detailed examples.