GO: Convert String To Integer

Learn how to convert a string to an integer using go (golang)

GO: Convert String To Integer

We use the Atoi function from the strconv package to convert a string to an integer.

// Create a string with the value of "25".
str := "25"

// Convert the string to an integer.
// Ignoring the error for this example.
number, _ := strconv.Atoi(str)

// Print out value and Type.
fmt.Printf("Type: %T, Value: %d\n", number, number)

Output:

Type: int, Value: 25