Go: Convert string to int64

Use strconv.ParseInt to convert a decimal string (base 10) and check that it fits into a 64-bit signed integer.

str := "123"
n, err := strconv.ParseInt(str, 10, 64)
if err == nil {
        fmt.Printf("%d of type %T", n, n)
}
// Output: 123 of type int64

Comments

Be the first to comment!