There are several ways of converting int32
into string
in golang.
- Using
fmt.Sprint(i)
(slowest)
import "fmt"
func main() {
var i int32
var s string
i = 10
s = fmt.Sprint(i)
fmt.Println(s)
}
// 10
- Using
strconv.FormatInt(int64(i), 10)
(faster)
import (
"fmt"
"strconv"
)
func main() {
var i int32
var s string
i = 10
s = strconv.FormatInt(int64(i), 10)
fmt.Println(s)
}
// 10
- Using
strconv.Itoa(int(i))
(fastest)
import (
"fmt"
"strconv"
)
func main() {
var i int32
var s string
i = 10
s = strconv.Itoa(int(i))
fmt.Println(s)
}
// 10
Popular knowhows
pubsub
gcloud
docker
3 years ago
go
golang
testing
2 years ago