Golang convert int to string example

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 we converted the convert…

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

In Golang, you can convert int to string  using the following functions.

  1. strconv.FormatInt
  2. 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


Print Share Comment Cite Upload Translate Updates
APA

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/

MLA
" » Golang convert int to string example." Deven | Sciencx - Sunday February 7, 2021, https://www.scien.cx/2021/02/07/golang-convert-int-to-string-example/
HARVARD
Deven | Sciencx Sunday February 7, 2021 » Golang convert int to string example., viewed ,<https://www.scien.cx/2021/02/07/golang-convert-int-to-string-example/>
VANCOUVER
Deven | Sciencx - » Golang convert int to string example. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/02/07/golang-convert-int-to-string-example/
CHICAGO
" » Golang convert int to string example." Deven | Sciencx - Accessed . https://www.scien.cx/2021/02/07/golang-convert-int-to-string-example/
IEEE
" » Golang convert int to string example." Deven | Sciencx [Online]. Available: https://www.scien.cx/2021/02/07/golang-convert-int-to-string-example/. [Accessed: ]
rf:citation
» Golang convert int to string example | Deven | Sciencx | 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.

You must be logged in to translate posts. Please log in or register.