Submitting the form below will ensure a prompt response from us.
Converting String to Integer in Golang is simple using the strconv.Atoi() function. This function takes a string input and returns the corresponding integer value. If the conversion fails, it returns an error. Here’s an example:
package main
import (
"fmt"
"strconv"
)
func main() {
str := "123"
num, err := strconv.Atoi(str)
if err != nil {
fmt.Println("Error:", err)
} else {
fmt.Println("Converted number:", num)
}
}
Output:
Converted number: 123
This will convert the string “123” to the integer 123.
Submitting the form below will ensure a prompt response from us.