spf13 / spf13/cast

ToInt have bad case

Open
#216 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Go
Stars
4k
Forks
337
Avg merge
15m
Merged PRs (30d)
1

Description

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
}

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in caste.go at trimZeroDecimal and trace how ToInt handles the string "00011". Verify that leading zeros are removed without changing the numeric value, and confirm the conversion returns 11 rather than 9.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.