Logo

Programming-Idioms

History of Idiom 22 > diff from v53 to v54

Edit summary for version 54 by programming-idioms.org:
[Go] +DemoURL

Version 53

2016-11-13, 22:37:04

Version 54

2016-11-13, 22:40:13

Idiom #22 Convert string to integer

Extract integer value i from its string representation s (in radix 10)

Illustration

Idiom #22 Convert string to integer

Extract integer value i from its string representation s (in radix 10)

Illustration
Extra Keywords
int base
Extra Keywords
int base
Imports
import "strconv"
Imports
import "strconv"
Code
i, err  := strconv.ParseInt(s, 10, 0)
Code
i, err := strconv.ParseInt(s, 10, 0)
Comments bubble
Radix 10. Third argument 0 means "fit in implementation-specific int". But result type is always int64.
Don't ignore the potential error err !
Comments bubble
Radix 10. Third argument 0 means "fit in implementation-specific int". But result type is always int64.
Don't ignore the potential error err !
Doc URL
http://golang.org/pkg/strconv/#ParseInt
Doc URL
http://golang.org/pkg/strconv/#ParseInt
Demo URL
https://play.golang.org/p/YkNeMgbLYe