Standard library / strconv

strconv.Atoi()

Parses decimal text into an int; accepts a leading sign but not surrounding whitespace. Returns a value and conversion error; range depends on int width. Expected stdout: '-42 <nil>\n'.

Formal Syntax & Structure

go syntaxgo
func Atoi(s string) (int, error)

Parameters & Attributes

NameTypeDescription
sstringInput text to parse, inspect or quote.

Return Value

(int, error)

Decoded or parsed value and error; inspect the error before using the result.

Working Example

Example Snippetgo
package main
import (  "fmt"  "strconv")
func main() {  n, e := strconv.Atoi("-42")  fmt.Println(n, e)}
Go Reference