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
+10.1k Golang : Compare files modify date example
+30.8k Golang : Interpolating or substituting variables in string examples
+7.5k Golang : How to stop user from directly running an executable file?
+9.8k Golang : Get current, epoch time and display by year, month and day
+12.6k Golang : Remove or trim extra comma from CSV
+8.1k Golang : How To Use Panic and Recover
+9.2k Golang : does not implement flag.Value (missing Set method)
+6.8k Golang : Muxing with Martini example
+35.9k Golang : Get file last modified date and time
+6.5k PHP : Shuffle to display different content or advertisement
+11.1k Golang : Fix go.exe is not compatible with the version of Windows you're running
+9k Golang : Handle sub domain with Gin