[Golang] Convert Integer to String via fmt.Sprintf


If you use strconv package, you can convert integer to string using following methods:

There is another way to do this, that is, use fmt.Sprintf

For example, assume variable i is either int or int64 type, you can convert it to string type as follows:

s := fmt.Sprintf("%d", i)

This is a small trick I found recently. You can try it yourself online:

Run Example on Go Playground