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

How to convert int to string in go language

王林
Release: 2023-02-08 11:48:35
Original
6463 people have browsed it

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))
Copy after login

The source code of this method is:

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

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)
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template