How to convert an int value to string in Go?
Use the strconv
package's Itoa
function.
For example:
package main
import (
"strconv"
"fmt"
)
func main() {
t := strconv.Itoa(123)
fmt.Println(t)
}
You can concat strings simply by +
'ing them, or by using the Join
function of the strings
package.
fmt.Sprintf("%v",value);
If you know the specific type of value use the corresponding formatter for example %d
for int
More info - fmt
fmt.Sprintf
, strconv.Itoa
and strconv.FormatInt
will do the job. But Sprintf
will use the package reflect
, and it will allocate one more object, so it's not an efficient choice.