react-component / react-component/input-number
getPrecision incorrectly calculates precision of decimal with scientific notation
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 323
- Forks
- 188
- Avg merge
- 20h 3m
- Merged PRs (30d)
- 1
Description
Reproduction:
-Navigate to http://react-component.github.io/input-number/examples?path=/story/rc-input-number--decimal
-Select decimal
-Enter '0.000000xx'
-Click out of the input
Expected - Value is preserved as entered
Actual - Value is truncated
This is due to a difference in the calculation of precision by the getPrecision function between a decimal using scientific notation and not, for example, getPrecision(0.0000001234) would return 10 but getPrecision(1.234e-7) would return 7, surely they should both return 10.
I figured this would be a simple fix, so I tested a simple change (see below) but a lot of tests broke with my change, although the failing test I added to cover the issue did pass.
if (valueString.indexOf('e-') >= 0) {
if(valueString.indexOf('.') >= 0) {
return parseInt(valueString.slice(valueString.indexOf('e-') + 2), 10) +
parseInt(valueString.slice(valueString.indexOf('.') + 1, valueString.indexOf('e-')).length);
}
return parseInt(valueString.slice(valueString.indexOf('e-') + 2), 10);
}
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The issue centers on getPrecision and the decimal example at the linked react-component story; start by locating that function and reproducing the scientific-notation case. Run the existing test suite, including the added regression test described in the issue, and consider the work done when both notation forms preserve the entered precision without breaking existing tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- react, typescript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100