How to fetch an Integer variable as String in GoLang? Last Updated : 22 Jun, 2020 Comments Improve Suggest changes Like Article Like Report 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 are the functions used to convert an integer to string: 1. strconv.Itoa(): To convert an int to a decimal string. // s == "60" s := strconv.Itoa(60) 2. strconv.FormatInt(): To format an int64 in a given base. var n int64 = 60 s := strconv.FormatInt(n, 10) // s == "60" (decimal) s := strconv.FormatInt(n, 16) // s == "3C" (hexadecimal) 3. strconv.FormatUint(): To return the string representation of x in the given base, i.e., 2 <= base <= 36. fmt.Println(strconv.FormatUint(60, 2)) // 111100 (binary) fmt.Println(strconv.FormatUint(60, 10)) // 60 (decimal) Example 1: C package main import ( "fmt" "strconv" ) func main() { var var_int int var_int = 23 // Itoa() is the most common // conversion from int to string. s1 := strconv.Itoa(var_int) fmt.Printf("%T %v\n", s1, s1) // format 23 int base 10 -> 23 s2 := strconv.FormatInt(int64(var_int), 10) fmt.Printf("%T %v\n", s2, s2) // return string representation // of 23 in base 10 -> 23 s3 := strconv.FormatUint(uint64(var_int), 10) fmt.Printf("%T %v\n", s3, s3) // concatenating all string->s1,s2 and s3. fmt.Println("Concatenating all strings: ", s1+s2+s3) } Output: string 23 string 23 string 23 Concatenating all strings: 232323 Example 2: C package main import ( "fmt" "strconv" ) func main() { var var_int int var_int = 50 // Itoa() is the most common // conversion from int to string. s1 := strconv.Itoa(var_int) fmt.Printf("%T %v\n", s1, s1) // format 50 int base 2 ->110010 s2 := strconv.FormatInt(int64(var_int), 2) fmt.Printf("%T %v\n", s2, s2) // return string representation // of 50 in base 16 -> 32 s3 := strconv.FormatUint(uint64(var_int), 16) fmt.Printf("%T %v\n", s3, s3) // concatenating all // string->s1,s2 and s3. fmt.Println("Concatenating all strings: ", s1+s2+s3) } Output: string 50 string 110010 string 32 Concatenating all strings: 5011001032 Comment More infoAdvertise with us Next Article How to fetch an Integer variable as String in GoLang? N nikki2398 Follow Improve Article Tags : Go Language Golang-Program Similar Reads Different Ways to Convert an Integer Variable to String in Golang Integer variable cannot be directly convert into String variable. In order to convert string to integer type in Golang , you have store value of integer variable as string in string variable. For this, we are using strconv and fmt package functions. 1. Itoa() Function:Â The Itoa stands for Integer t 3 min read How to Convert string to integer type in Golang? 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 2 min read How to print struct variables data in Golang? A struct (Structure) is a user-defined type in Golang that contains a collection of named fields/properties which creates own data types by combining one or more types. Also, this concept is generally compared with the classes in object-oriented programming. A struct has different fields of the same 2 min read How to declare and access pointer variable in Golang? Pointers in Go programming language or Golang is a variable which is used to store the memory address of another variable. Pointers in Golang is also termed as the special variables. The variables are used to store some data at a particular memory address in the system. The memory address is always 3 min read How to Read a File Line by Line to String in Golang? To read a file line by line the bufio package Scanner is used. Let the text file be named as sample.txt and the content inside the file is as follows: GO Language is a statically compiled programming language, It is an open-source language. It was designed at Google by Rob Pike, Ken Thompson, and Ro 2 min read How to Trim a String in Golang? In Go, strings are UTF-8 encoded sequences of variable-width characters, unlike some other languages like Java, python and C++. Go provides several functions within the strings package to trim characters from strings.In this article we will learn how to Trim a String in Golang.Examples := "@@Hello, 2 min read How to Get the String in Specified Base in Golang? Go language provides inbuilt support to implement conversions to and from string representations of basic data types by strconv Package. This package provides a FormatInt() function which is used to return the string representation of x in the given base, i.e., 2 <= base <= 36. Here, the resul 2 min read Converting a string variable into Boolean, Integer or Float type in Golang Various types of string conversions are needed while performing tasks in Golang. Package strconv is imported to perform conversions to and from string. String to Boolean Conversion ParseBool is used to convert string to boolean value. It accepts 1, t, T, TRUE, true, True as true and 0, f, F, FALSE, 3 min read How to Split a String in Golang? In Go language, strings differ from other languages like Java, C++, and Python. A string in Go is a sequence of variable-width characters, with each character represented by one or more bytes using UTF-8 encoding. In Go, you can split a string into a slice using several functions provided in the str 3 min read How to use Array Reverse Sort Functions for Integer and Strings in Golang? Go language provides inbuilt support implementation of basic constants and run-time reflection to operate sort package. Golang is the ability for functions to run independently of each other. With the help of this function we can easily sort integer and string by importing "sort" package. Basically, 1 min read Like