adobe / adobe/spectrum-web-components
[Bug]: Precision error in sp-number-field with decimal step increments
- Dominant language
- TypeScript
- Stars
- 1.5k
- Forks
- 262
- Avg merge
- 3d 10h
- Merged PRs (30d)
- 68
Description
### Code of conduct
- [X] I agree to follow this project's code of conduct.
### Impacted component(s)
sp-number-field
### Expected behavior
When using arrow keys or a mouse scroll wheel to increment the value is to adjust the value in steps exactly as defined by the 'step' attribute.
### Actual behavior
Value is experiencing floating-point precision issues. When the value is adjusted via the arrow keys or mouse scroll wheel, and the step is set to a decimal, the resulting value displays excessive decimal places, such as "0.00100000000...".
### Screenshots
### What browsers are you seeing the problem in?
Chrome
### How can we reproduce this issue?
1. https://opensource.adobe.com/spectrum-web-components/storybook/?path=/story/number-field--default&args=value:0.001
2. Set 'step' attribute value to a decimal value (e.g., '0.001').
3. Use the arrow keys or mouse scroll wheel to increment or decrement the value. Observe that the displayed value shows more decimal places than expected (e.g., "0.0019999999999" instead of "0.001").
### Sample code that illustrates the problem
_No response_
### Logs taken while reproducing problem
_No response_
Contributor guide
Research direction
Start with the sp-number-field default story in the linked Storybook reproduction and inspect the component behavior triggered by arrow keys or mouse-wheel changes. Reproduce with a decimal step such as 0.001, then verify that increments and decrements display the exact step precision rather than excessive floating-point digits.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100