Get in Touch With Us

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:

Convert String to Integer in an Golang

        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.

About Author

Jayanti Katariya is the CEO of Moon Technolabs, a fast-growing IT solutions provider, with 18+ years of experience in the industry. Passionate about developing creative apps from a young age, he pursued an engineering degree to further this interest. Under his leadership, Moon Technolabs has helped numerous brands establish their online presence and he has also launched an invoicing software that assists businesses to streamline their financial operations.

Related Q&A