You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The text was updated successfully, but these errors were encountered:
cbajohr
changed the title
Casting string with 0 in prefix to int does not work
Casting a string to int with a 0 in prefix does not work as expected
Mar 11, 2019
The problem is the strconv.ParseInt(s, 0, 0) in the ToInt methods. When I use strconv.ParseInt(s, 10, 0) instead it works like a charm.
Like the strconv.ParseInt comment says:
If base == 0, the base is implied by the string's prefix: base 16 for "0x", base 8 for "0", and base 10 otherwise. For bases 1, below 0 or above 36 an error is returned.
I think strconv.ParseInt(s, 10, 0) is the right expected behavior of a standard ToInt casting. I will add a pull request later today, to fix that problem.
When I cast a string with prefixed 0 like "0123" with cast.ToInt("0123"), it results into 83 instead of the expected 123
Example code:
The text was updated successfully, but these errors were encountered: