Golang strconv.Itoa() is equivalent to the FormatInt(int64(i), 10) function “used to get the string representation of the given integer (int).”
Syntax
func Itoa(i int) string
Parameters
The Itoa() function takes an input i of type integer.
Return Value
The strconv.Itoa() function returns a string that represents i.
Example 1: How to Use strconv.Itoa() function
package main
import (
"fmt"
"strconv"
)
func main() {
str1 := strconv.Itoa(19)
fmt.Printf("%T, %v\n", str1, str1)
str2 := strconv.Itoa(21)
fmt.Printf("%T, %v\n", str2, str2)
}
Output
string, 19
string, 21
Example 2: Passing a negative integer
Pass a negative integer as an input to the strconv.Itoa() function.
package main
import (
"fmt"
"strconv"
)
func main() {
int1 := -19
fmt.Printf("Output: %d \n", int1)
fmt.Printf("Data Type: %T \n", int1)
fmt.Println("After conversion:")
str1 := strconv.Itoa(int1)
fmt.Printf("Output: %v \n", str1)
fmt.Printf("Output: %T \n", str1)
}
Output
Output: -19
Data Type: int
After conversion:
Output: -19
Output: string
That’s it.
Related posts

Krunal Lathiya is a seasoned Computer Science expert with over eight years in the tech industry. He boasts deep knowledge in Data Science and Machine Learning. Versed in Python, JavaScript, PHP, R, and Golang. Skilled in frameworks like Angular and React and platforms such as Node.js. His expertise spans both front-end and back-end development. His proficiency in the Python language stands as a testament to his versatility and commitment to the craft.