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.1k Golang : Calculate BMI and risk category
+11.5k Golang : Search and extract certain XML data example
+15.5k Golang : Convert slice to array
+10k Golang : Sieve of Eratosthenes algorithm
+17k Golang : Get command line arguments
+20.2k Golang : Get password from console input without echo or masked
+5.8k Golang : How to setup a disk space used monitoring service with Telegram bot
+9.1k Golang : Translate language with language package example
+10.5k Golang : Format numbers to nearest thousands such as kilos millions billions and trillions
+12.5k Golang : Get constant name from value
+7.1k Golang : Gomobile init produce "iphoneos" cannot be located error
+31.2k Golang : Convert []string to []byte examples