How to Convert string to integer type in Golang? Last Updated : 28 Apr, 2025 Comments Improve Suggest changes Like Article Like Report Strings in Golang is a sequence of variable-width characters where each and every character is represented by one or more bytes using UTF-8 Encoding. In Go language, both signed and unsigned integers are available in four different sizes. In order to convert string to integer type in Golang, you can use the following methods. 1. Atoi() Function: The Atoi stands for ASCII to integer and returns the result of ParseInt(s, 10, 0) converted to type int. Syntax: func Atoi(s string) (int, error) Example: Go // Go program to illustrate how to // Convert string to the integer type package main import ( "fmt" "strconv" ) func main() { str1 := "123" // using ParseInt method int1, err := strconv.ParseInt(str1, 6, 12) fmt.Println(int1) // If the input string contains the integer // greater than base, get the zero value in return str2 := "123" int2, err := strconv.ParseInt(str2, 2, 32) fmt.Println(int2, err) } Output: 123 0 strconv.Atoi: parsing "12.3": invalid syntax 2. ParseInt() Function: The ParseInt interprets a string s in the given base (0, 2 to 36) and bit size (0 to 64) and returns the corresponding value i. Syntax: func ParseInt(s string, base int, bitSize int) (i int64, err error) Example: Go // Go program to illustrate how to // Convert string to the integer type package main import ( "fmt" "strconv" ) func main() { str1 := "123" // using ParseInt method int1, err := strconv.ParseInt(str1, 6, 12) fmt.Println(int1) // If the input string contains the integer // greater than base, get the zero value in return str2 := "123" int2, err := strconv.ParseInt(str2, 2, 32) fmt.Println(int2, err) } Output: 51 0 strconv.ParseInt: parsing "123": invalid syntax Comment More infoAdvertise with us Next Article How to Convert string to integer type in Golang? S SHUBHAMSINGH10 Follow Improve Article Tags : Go Language Golang-Program Similar Reads How to Convert string to float type in Golang? ParseFloat function is an in-build function in the strconv library which converts the string type into a floating-point number with the precision specified by bit size. Example: In this example the same string -2.514 is being converted into float data type and then their sum is being printed. Once i 1 min read How to Convert String to Number in TypeScript? In TypeScript, converting a string to a number is a common operation that can be accomplished using several different methods. Each method offers unique advantages and can be chosen based on the specific requirements of your application. Below are the approaches to convert string to number in TypeSc 4 min read How to convert Int data type to Float in Golang? In Golang, the data types are bound to variables rather than the values, which means that, if you declare a variable as int, then you can store only integer type value in it, you cant assign character or string in it unless you convert the data type to required data type. To convert an integer data 2 min read How to Get Int Type Random Number in Golang? Go language provides inbuilt support for generating random numbers of the specified type with the help of a math/rand package. This package implements pseudo-random number generators. These random numbers are generated by a source and this source produces a deterministic sequence of values whenever 2 min read How to fetch an Integer variable as String in GoLang? To fetch an Integer variable as String, Go provides strconv package which has methods that return a string representation of int variable. There is nothing like an integer variable is converted to a string variable, rather, you have to store integer value as a string in a string variable. Following 2 min read Like