Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: NumberInput: Inconsistent decimal precision handling #18591

Open
2 tasks done
riddhybansal opened this issue Feb 14, 2025 · 0 comments · May be fixed by #18670
Open
2 tasks done

[Bug]: NumberInput: Inconsistent decimal precision handling #18591

riddhybansal opened this issue Feb 14, 2025 · 0 comments · May be fixed by #18670

Comments

@riddhybansal
Copy link
Contributor

Package

@carbon/react

Browser

No response

Package version

Storybook version

React version

No response

Description

Current Behavior

When incrementing decimal numbers by 1:

  • 12.01 + 1 correctly becomes 13.01
  • 15.01 + 1 incorrectly becomes 16.009999999999998

This is due to JavaScript's IEEE 754 floating-point precision limitations, where some decimal numbers cannot be precisely represented in binary.

Expected Behavior

All decimal numbers should maintain their precision when incrementing/decrementing, regardless of the base number:

  • 12.01 + 113.01
  • 15.01 + 116.01

The issue stems from floating-point precision in JavaScript. While users can work around this in their codebase, handling this at the library level would:

Provide consistent behavior across all implementations
Reduce maintenance burden for users
Ensure reliable decimal operations for financial/scientific applications

Reproduction/example

NA

Steps to reproduce

  • Go to Number Input
  • Enter "15.01"
  • Click increment button once
  • Value becomes "16.009999999999998" instead of "16.01"

Suggested Severity

Severity 4 = Unrelated to a user task, has a workaround or does not need a workaround.

Application/PAL

No response

Code of Conduct

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: ⏱ Backlog
Development

Successfully merging a pull request may close this issue.

1 participant