Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

strconv.Atoi() appends <nil> to the end of my number – Golang

Pretty simple question. I’m using strconv.Atoi to convert a string value to an integer, but it returns the number and then a <nil> value to the end for some reason (Like this: 1 <nil>). I don’t see anything online about this.

Here’s the relevant code:

fmt.Println(strconv.Atoi(tokens[index + 2][4:]))

Any help would be greatly appreciated!

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

strconv.Atoi returns an integer and an error

package main
import (
  "fmt"
  "strconv"
)

func main() {
  number, err := strconv.Atoi("5")
  fmt.Println(number)
  fmt.Println(err)
}

Prints

5
<nil>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading