int from string in go [duplicate]
Asked Answered
M

2

5

What's the function to create a int value from string

i := ???.????( "10" )
Magical answered 20/4, 2010 at 6:14 Comment(0)
J
8

Import the strconv package (src/pkg/strconv), then use strconv.Atoi("10")

Jelks answered 20/4, 2010 at 6:19 Comment(0)
M
0

Some other options:

package main
import "fmt"

func main() {
   var n int
   fmt.Sscan("100", &n)
   fmt.Println(n == 100)
}
package main
import "strconv"

func main() {
   n, e := strconv.ParseInt("100", 10, 64)
   if e != nil {
      panic(e)
   }
   println(n == 100)
}
Malindamalinde answered 14/3, 2021 at 18:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.