Skip to content

Fix value step for number inputs when using decimals#599

Merged
Flaminel merged 2 commits into
mainfrom
fix_decimal_input
May 3, 2026
Merged

Fix value step for number inputs when using decimals#599
Flaminel merged 2 commits into
mainfrom
fix_decimal_input

Conversation

@Flaminel

@Flaminel Flaminel commented May 3, 2026

Copy link
Copy Markdown
Contributor

Summary by Sourcery

Bug Fixes:

  • Fix number input step calculations so values with decimal steps are rounded to the correct precision when incrementing or decrementing.

@Flaminel

Flaminel commented May 3, 2026

Copy link
Copy Markdown
Contributor Author

@sourcery-ai review

@sourcery-ai

sourcery-ai Bot commented May 3, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Ensures 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 handling

classDiagram
  class NumberInputComponent {
    +blurred(event)
    +increment() void
    +decrement() void
    -stepDecimals() number
    +step() number
    +value() number
    +max() number
    +min() number
    +disabled() boolean
  }
Loading

File-Level Changes

Change Details Files
Normalize increment/decrement operations to the step's decimal precision to avoid floating‑point artifacts for decimal steps.
  • Introduce a helper that derives the number of decimal places from the configured step value.
  • Use toFixed with the computed precision when adding the step in increment, then convert back to a number.
  • Use toFixed with the computed precision when subtracting the step in decrement, then convert back to a number.
code/frontend/src/app/ui/number-input/number-input.component.ts

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue, and left some high level feedback:

  • 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.
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>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread code/frontend/src/app/ui/number-input/number-input.component.ts Outdated
@Flaminel Flaminel merged commit c1d2790 into main May 3, 2026
10 of 11 checks passed
@Flaminel Flaminel deleted the fix_decimal_input branch May 3, 2026 20:11
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

Successfully merging this pull request may close these issues.

1 participant