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 collect information about garbage collection?
Subtract N number of Year, Month, Day, Hour, Minute, Second, Millisecond, Microsecond and Nanosecond to current date-time.
Find out how many logical processors used by current process
How to create Map using the make function in Go?
Golang import package inside package
How to Unmarshal nested JSON structure?
Replace first occurrence of string using Regexp
How to read/write from/to file in Golang?
How to compare equality of struct, slice and map?
How to use Ellipsis (...) in Golang?