Skip to content

Conversation

@lzeiml
Copy link
Collaborator

@lzeiml lzeiml commented Jan 28, 2026

💡 What is the current behavior?

When using step="0.1" or similar, the stepper buttons sometimes cause floating point errors, resulting in values like 0.999999...

GitHub Issue Number: #2360

🆕 What is the new behavior?

Fixed the floating point error

🏁 Checklist

A pull request can only be merged if all of these conditions are met (where applicable):

  • 🦮 Accessibility (a11y) features were implemented
  • 🗺️ Internationalization (i18n) - no hard coded strings
  • 📲 Responsiveness - components handle viewport changes and content overflow gracefully
  • 📕 Add or update a Storybook story
  • 📄 Documentation was reviewed/updated siemens/ix-docs
  • 🧪 Unit tests were added/updated and pass (pnpm test)
  • 📸 Visual regression tests were added/updated and pass (Guide)
  • 🧐 Static code analysis passes (pnpm lint)
  • 🏗️ Successful compilation (pnpm build, changes pushed)

@changeset-bot
Copy link

changeset-bot bot commented Jan 28, 2026

⚠️ No Changeset found

Latest commit: 29bfaa4

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @lzeiml, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request resolves a critical floating-point precision issue within the ix-number-input component, specifically when users interact with the stepper buttons using decimal step values. By introducing a new utility function to determine decimal places and applying careful rounding during step operations, the component now provides accurate numerical results, enhancing its reliability for applications requiring precise decimal input.

Highlights

  • Floating Point Error Fix: Implemented a fix for floating-point errors in the ix-number-input component when using stepper buttons with decimal step values, which previously resulted in values like 0.999999....
  • Decimal Place Calculation Utility: Introduced a new private helper function getDecimalPlaces within number-input.tsx to accurately determine the number of decimal places in a given number.
  • Precise Rounding in Stepper Operations: Modified the handleStepOperation method to apply precise rounding using toFixed based on the maximum decimal places of the current value and the step value, ensuring accurate numerical results.
  • New Regression Test: Added a new regression test to form-ready.ct.ts to specifically validate that the ix-number-input stepper correctly handles decimal steps without introducing precision issues.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@sonarqubecloud
Copy link

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request effectively addresses the floating point precision error when using the stepper buttons in the number input component. The approach of rounding the value based on the decimal places of the current value and the step is correct. The addition of a regression test is also great for ensuring this bug doesn't reappear. My only concern is with the implementation of the new getDecimalPlaces helper function, which doesn't correctly handle numbers represented in scientific notation. I've left a suggestion to make it more robust.

Comment on lines +345 to +352
private getDecimalPlaces(num: number): number {
const str = num.toString();
const decimalIndex = str.indexOf('.');
if (decimalIndex === -1) {
return 0;
}
return str.length - decimalIndex - 1;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The current implementation of getDecimalPlaces can produce incorrect results for very small numbers that are represented in scientific notation by toString(). For example, for a number like 1e-7 (0.0000001), toString() returns '1e-7', which doesn't contain a . and your function will incorrectly return 0 decimal places.

This can lead to incorrect rounding when using very small step values.

Consider a more robust implementation that can handle scientific notation. The suggested code uses a regular expression to correctly parse integers, decimals, and numbers in scientific notation.

  private getDecimalPlaces(num: number): number {
    const match = ('' + num).match(/(?:\.(\d+))?(?:[eE]([+-]?\d+))?$/);
    if (!match) {
      return 0;
    }
    return Math.max(
      0,
      (match[1] ? match[1].length : 0) - (match[2] ? +match[2] : 0)
    );
  }

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.

2 participants