Golang : convert(cast) string to integer value
To convert or cast a string to integer value, just use the strconv.Atoi()
function. Below is the code example to demonstrate how to convert string to integer value.
package main
import (
"fmt"
"strconv"
)
func main() {
var i int
i, _ = strconv.Atoi("123")
fmt.Println(i)
}
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
+9.8k Golang : Sieve of Eratosthenes algorithm
+15k Golang : Generate QR codes for Google Authenticator App and fix "Cannot interpret QR code" error
+23.5k Golang : Change file read or write permission example
+12.2k Facebook PHP getUser() returns 0
+17.8k Golang : When to use public and private identifier(variable) and how to make the identifier public or private?
+9.2k Golang : Wait and sync.WaitGroup example
+8k Golang : io.Reader causing panic: runtime error: invalid memory address or nil pointer dereference
+10.4k Golang : Simple file scaning and remove virus example
+10.5k Golang : Surveillance with web camera and OpenCV
+11.7k Golang : Pass database connection to function called from another package and HTTP Handler
+6.6k Golang : Convert source code to assembly language
+5.8k Golang : Reverse by word