We can’t perform operations like int
values to string
.
We can convert an int
value to a string
data type using the strconv.Itao(int)
method.
strconv.Itao(int)
strconv.Itao(int)
receives an int
value as a parameter.
strconv.Itao(int)
returns a string
value.
package main import ( "fmt" "strconv" ) func main() { i := 10 fmt.Println(i + 2) s2 := strconv.Itoa(i) fmt.Println(s2 + "2") }
In the example above:
import (
"fmt"
"strconv"
)
Then,
In line 10, we print the int
value (original value + 2).
In line 11, we pass the int
value we want to convert.
s2 := strconv.Itoa(i)
string
value which returns from the function concatenated with “2”.RELATED TAGS
CONTRIBUTOR
View all Courses