This content originally appeared on CodeSource.io and was authored by Deven
In Golang, you can convert int to string using the following functions.
- strconv.FormatInt
- strconv.Itoa
1. Golang convert int to string using strconv.Itoa
package main
import (
"fmt"
"strconv"
)
func main() {
convert := 9278
str1 := strconv.Itoa(convert)
fmt.Println(str1)
}
we converted the convert
variable into a string using Itoa
method. the above code ouputs 9278
2. Golang convert int to string using strconv.FormatInt
package main
import (
"fmt"
"strconv"
)
func main() {
convert2 := 1234
str2 := strconv.FormatInt(int64(convert2), 10)
fmt.Println(str2)
}
we converted the convert2
variable into a string using FormatInt
method. the above code outputs 1234
. check out Golang convert string to int – example article to do vice versa.
The post Golang convert int to string example appeared first on CodeSource.io.
This content originally appeared on CodeSource.io and was authored by Deven
Deven | Sciencx (2021-02-07T17:29:07+00:00) Golang convert int to string example. Retrieved from https://www.scien.cx/2021/02/07/golang-convert-int-to-string-example/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.