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
+11.8k Golang : Get remaining text such as id or filename after last segment in URL path
+9k Golang : How to check if a string with spaces in between is numeric?
+42.6k Golang : Convert []byte to image
+6.1k Unix/Linux : Use netstat to find out IP addresses served by your website server
+5.2k Golang : If else example and common mistake
+14.2k Golang : How to filter a map's elements for faster lookup
+5.4k Golang : Frobnicate or tweaking a string example
+10.9k Golang : Fix - does not implement sort.Interface (missing Len method)
+12.7k Golang : Get terminal width and height example
+17.2k Golang : Clone with pointer and modify value
+8.5k Golang : Combine slices but preserve order example
+25.5k Golang : missing Mercurial command