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
+6.7k Setting $GOPATH environment variable for Unix/Linux and Windows
+3.9k Unix/Linux : How to pipe/save output of a command to file?
+17k Golang : Iterating Elements Over A List
+4.7k Swift : Get substring with rangeOfString() function example
+16.7k Golang : Convert IPv4 address to decimal number(base 10) or integer
+4.6k Golang : What is StructTag and how to get StructTag's value?
+11k Golang : Flush and close file created by os.Create and bufio.NewWriter example
+32.5k Golang : How to check if slice or array is empty?
+7.9k Golang : GMail API create and send draft with simple upload attachment example
+13.7k Golang : Get HTTP protocol version example
+19.7k Golang : How to read float value from standard input ?
+16.2k Golang : Parse date string and convert to dd-mm-yyyy format