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
+7.8k Golang : Build and compile multiple source files
+3.8k JavaScript : Rounding number to decimal formats to display currency
+14.2k Golang : Intercept Ctrl-C interrupt or kill signal and determine the signal type
+25k Golang : Convert file content into array of bytes
+30.5k Golang : Copy directory - including sub-directories and files
+14.7k Golang : Read a file line by line
+11.1k Golang : Add ASCII art to command line application launching process
+16.5k Golang : How to log each HTTP request to your web server?
+8k Golang : Generate EAN barcode
+8.9k Golang : Get current, epoch time and display by year, month and day
+13.3k Golang : Parsing or breaking down URL
+7.3k Python : Fix SyntaxError: Non-ASCII character in file, but no encoding declared