Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ToInt have bad case #216

Open
ypshe opened this issue Apr 15, 2024 · 1 comment
Open

ToInt have bad case #216

ypshe opened this issue Apr 15, 2024 · 1 comment

Comments

@ypshe
Copy link

ypshe commented Apr 15, 2024

for example,string is "00011",handle ToInt("00011"),want to get int value is 11,now return 9;

need exchange caste.go trimZeroDecimal method,first trimleft zero

func trimZeroDecimal(s string) string {
s = strings.TrimLeft(s, "0")
var foundZero bool
for i := len(s); i > 0; i-- {
switch s[i-1] {
case '.':
if foundZero {
return s[:i-1]
}
case '0':
foundZero = true
default:
return s
}
}
return s
}

@bagualing
Copy link

Cast package treats this value as an octal number.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants