[Go] Convert a string to an int

Created on November 30, 2026

Use strconv.Atoi to parse a decimal string as an int. Check the returned error before using the value.

package main

import (
    "fmt"
    "strconv"
)

func main() {
    intNumber, err := strconv.Atoi("111")
    if err != nil {
        panic("Error")
    }
    fmt.Printf("%d", intNumber)
}

Output

111
Go