Home>Article>Backend Development> How to convert int to string in go language

How to convert int to string in go language

王林
王林 Original
2021-02-04 14:10:07 6378browse

Go language method to convert int to string: 1. Use "fmt.Println(strconv.Itoa(100))" to convert integer to string; 2. Use "i, _ := strconv .Atoi("100") fmt.Println(i)" can be used to convert string to integer.

How to convert int to string in go language

The operating environment of this article: windows10 system, Go 1.11.2, thinkpad t480 computer.

How to convert int to string in Go language?

Integer to string

fmt.Println(strconv.Itoa(100))

The source code of this method is:

// Itoa is shorthand for FormatInt(i, 10). func Itoa(i int) string { return FormatInt(int64(i), 10) }

It can be seen that it is a simple implementation of the FormatInt method.

Convert string to integer

i, _ := strconv.Atoi("100") fmt.Println(i)

Related recommendations:golang tutorial

The above is the detailed content of How to convert int to string in go language. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn