String to int (not int64) using ParseInt()/Atoi()

The bitSize argument specifies the integer type that the result must fit into

This means the int64 result can be safely casted to your integer type:

i64, _ := strconv.ParseInt("42", 10, 64)

or

i64, _ := strconv.ParseInt("42", 10, 32)
var i32 int32 = i64 // cast to int32

or

i64, _ := strconv.ParseInt("42", 10, 0)
var i int = i64 // cast to int

int is either int32 or int64 depending on your system. With the bitSize 0 you make ParseInt choose the right type for you (32 or 64).

1 Like