Fix value step for number inputs when using decimals#599
Merged
Conversation
Contributor
Author
|
@sourcery-ai review |
Reviewer's guide (collapsed on small PRs)Reviewer's GuideEnsures numeric increments/decrements respect the decimal precision of the configured step so number inputs do not accumulate floating‑point precision errors when using decimal steps. Class diagram for updated NumberInputComponent decimal step handlingclassDiagram
class NumberInputComponent {
+blurred(event)
+increment() void
+decrement() void
-stepDecimals() number
+step() number
+value() number
+max() number
+min() number
+disabled() boolean
}
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- The
stepDecimals()helper currently infers precision fromthis.step().toString(), which may produce unexpected results for values represented in exponential notation (e.g.1e-3) or with floating-point artifacts; consider deriving the precision from the original input configuration or allowing an explicit precision override when needed. - The increment and decrement logic are now almost identical aside from the sign; consider extracting a shared helper (e.g.
applyStep(direction: 1 | -1)) to avoid duplication and keep future changes to the rounding/clamping logic in a single place.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The `stepDecimals()` helper currently infers precision from `this.step().toString()`, which may produce unexpected results for values represented in exponential notation (e.g. `1e-3`) or with floating-point artifacts; consider deriving the precision from the original input configuration or allowing an explicit precision override when needed.
- The increment and decrement logic are now almost identical aside from the sign; consider extracting a shared helper (e.g. `applyStep(direction: 1 | -1)`) to avoid duplication and keep future changes to the rounding/clamping logic in a single place.
## Individual Comments
### Comment 1
<location path="code/frontend/src/app/ui/number-input/number-input.component.ts" line_range="55-58" />
<code_context>
this.blurred.emit(event);
}
+ private stepDecimals(): number {
+ const s = this.step().toString();
+ const dot = s.indexOf('.');
+ return dot === -1 ? 0 : s.length - dot - 1;
+ }
+
</code_context>
<issue_to_address>
**issue (bug_risk):** Using `toString()` on `this.step()` may miscount decimals when the value is represented in exponential notation.
For example, with a step of `1e-7`, `this.step().toString()` returns `'1e-7'`, so `stepDecimals()` becomes `1` instead of `7`, which then breaks rounding in `increment`/`decrement`. Instead of relying on `toString()`, derive the decimal count from a normalized representation (e.g., detect non-integers and scale until integer, or use `toFixed` with a safe upper bound and strip trailing zeros).
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary by Sourcery
Bug Fixes: