Skip to content

bug(core/number-input): Fix stepper floating point error#2363

Open
lzeiml wants to merge 11 commits intomainfrom
bug/3881_number-input-floating-point-error
Open

bug(core/number-input): Fix stepper floating point error#2363
lzeiml wants to merge 11 commits intomainfrom
bug/3881_number-input-floating-point-error

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

🦋 Changeset detected

Latest commit: d0c34c8

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 5 packages
Name Type
@siemens/ix Patch
@siemens/ix-angular Patch
@siemens/ix-docs Patch
@siemens/ix-react Patch
@siemens/ix-vue Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another 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.

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.

Copy link
Collaborator

@nuke-ellington nuke-ellington left a comment

Choose a reason for hiding this comment

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

Focus input with step 0.1 -> insert e.g. 1e5 -> Arrow Up -> will set input value to 0.1

@lzeiml
Copy link
Collaborator Author

lzeiml commented Mar 3, 2026

Focus input with step 0.1 -> insert e.g. 1e5 -> Arrow Up -> will set input value to 0.1

Fixed

@sonarqubecloud
Copy link

sonarqubecloud bot commented Mar 3, 2026

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