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

Decimal rounding up #838

Open
6 tasks
hamiidrahmani opened this issue Apr 23, 2024 · 3 comments
Open
6 tasks

Decimal rounding up #838

hamiidrahmani opened this issue Apr 23, 2024 · 3 comments

Comments

@hamiidrahmani
Copy link

hamiidrahmani commented Apr 23, 2024

Describe the issue and the actual behavior

Package rounded up the number in case I passed the decimal scale, But this should not happen. In my opinion, the main number should not be changed or should have a new prop to handle the rounding mode.

Describe the expected behavior

consider:
<NumericFormat value={0.99813} decimalScale={2} />
It returns an input with the value 1.00 but I expect the final number to be 0.99, I expect it just removes additional decimals, not rounding the main value up.

Provide a CodeSandbox link illustrating the issue

https://codesandbox.io/p/sandbox/value-demo-forked-y4nw27?file=%2Fsrc%2FApp.js%3A17%2C5

Provide steps to reproduce this issue

Please check the browsers where the issue is seen

  • Chrome
  • Chrome (Android)
  • Safari (OSX)
  • Safari (iOS)
  • Firefox
  • Firefox (Android)
@hamiidrahmani
Copy link
Author

After tracing it, I discovered a function in the utils file called roundToPrecision, in which the toFixed function is used in this function. Is there a solution to truncate the main number using the decimalScale instead of using the toFixed function?

@s-yadav
Copy link
Owner

s-yadav commented Apr 28, 2024

Hey @hamiidrahmani this is intentional behaviour added on the library to round the value prop, and not allow user to type beyond the provided decimalScale.
There are plans to make API for decimal precisions more equivalent to Intl.NumberFormatand we will introduce maximumSignificantDigits, minimumSignificantDigits and roundingMode prop, using which you can achieve this.

But meanwhile, will suggest to trim the decimal part on consumer land.

@hamiidrahmani
Copy link
Author

Hey @s-yadav, First of all, thanks for your time and consideration.
I want you to know it works properly in version 4.7.3 and I found it after I updated the package. Also, the package is used in a large-scale financial project and It is not reasonable for me to trim the decimal part.

so I have a question: What is your time estimation for implementing these changes?

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

No branches or pull requests

2 participants