How to convert string to int in Golang

The method of converting string to int in go language: 1. Convert string to int by “int, err:=strconv.Atoi()” method; 2. Convert string to int by “int64, err:=strconv.ParseInt…” method Convert to int64.

The operating environment of this article: Windows7 system, Go1.11.2, Dell G3 computer.

Recommended: “golang tutorial”

How to convert between strings and various int types in golang

Go language implements string conversion int

Convert string to int:

int, err := strconv.Atoi(string)

Convert string to int64:

int64, err := strconv.ParseInt(string, 10, 64)

Convert int to string:

string := strconv.Itoa(int)

Convert int64 to string:

string := strconv.FormatInt(int64,10)

Leave a Reply

Your email address will not be published. Required fields are marked *