How to fetch an Integer variable as String in Go?
The Go strconv package has methods which returns string representation of integer variable. You can't convert an integer variable in to string variable. You have to store value of integer variable as string in string variable.
Example
package main
import (
"strconv"
"fmt"
)
func main() {
fmt.Println("\n#######################\n")
var intVar int
intVar = 258
str1 := strconv.Itoa(intVar)
fmt.Printf("%T %v\n",str1,str1)
fmt.Println("\n#######################\n")
str2 := strconv.FormatUint(uint64(intVar), 10)
fmt.Printf("%T %v\n",str2,str2)
fmt.Println("\n#######################\n")
str3 := strconv.FormatInt(int64(intVar), 10)
fmt.Printf("%T %v\n",str3,str3)
fmt.Println("\n#######################\n")
fmt.Println("str1+str2+str3 :",str1 + str2 + str3)
}
FormatInt returns the string representation of i in the given base, for 2 <= base <= 36. The result uses the lower-case letters 'a' to 'z' for digit values >= 10.
Itoa is shorthand for FormatInt(int64(i), 10).
Most Helpful This Week
How to use wildcard or a variable in our URL for complex routing?
Simple function with parameters in Golang
How to iterate over a Map using for loop in Go?
Select single argument from all arguments of variadic function
Regular expression to validate the date format in "dd/mm/yyyy"
Split a character string based on change of character