Golang : convert int to string
While working on previous tutorial on displaying struct
values in string format with a method. I stumbled upon an age old question many programmers will eventually face one day. How to convert type integer to string.
In Go, it is pretty simple. Just use strconv.Itoa()
function to convert integer to string.
Here is the source code example :
package main
import (
"strconv"
"fmt"
)
func main() {
age := 12
// will NOT display properly
fmt.Println(string(age))
// convert int to string
agestr := strconv.Itoa(age)
// will display properly
fmt.Println(agestr)
}
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+28.6k Golang : How to get HTTP request header information?
+11k Android Studio : Highlight ImageButton when pressed on example
+26k Golang : Record voice(audio) from microphone to .WAV file
+11k Golang : Encrypt and decrypt data with x509 crypto
+10.7k Golang : Split strings into command line arguments
+5.4k Golang : Convert an executable file into []byte example
+4.9k Golang : Launching your executable inside a console under Linux
+7k Golang : Multiplexer with net/http and map
+5.3k Golang : Break string into a slice of characters example
+15k Golang : Execute terminal command to remote machine example
+22.7k Golang : Find biggest/largest number in array