Golang: convert between int, int64 and string

int to string

s := strconv.Itoa(123)

int64 to string

var n int64 = 123
s := strconv.FormatInt(n, 10) // s == "123" (decimal)
var n int64 = 123
s := strconv.FormatInt(n, 16) // s == "7b" (hexadecimal)

string to int

s := "123"
n, err := strconv.Atoi(s)

string to int64

s := "123"
n, err := strconv.ParseInt(s, 10, 64)

發表迴響

你的電子郵件位址並不會被公開。 必要欄位標記為 *