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

Add support for minDecimalScale #752

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

RayzorFlash
Copy link

Describe the issue/change

  • In many currency-related use cases, a minimal decimal precision of 2 digits is common. This way, large numbers get displayed with two padded zeroes (i.e. $1,000,000.00) while small numbers support added precision of up-to n digits ($0.89765412 if n=8)

  • This functionality is not currently possible with this library due to fixedDecimalScale enforcing EXACTLY n digits of precision, while decimalScale provides only a MAXIMUM number of digits when used on its own

  • In a future release (since it would be a breaking change) we can probably remove fixedDecimalScale and use only minDecimalScale and decimalScale to clamp the bounds of precision and satisfy every use case

Example usage (If applicable)

<NumberFormat minDecimalScale={2} decimalScale={8} value={24}/> 

Please check which browsers were used for testing

  • Chrome
  • Chrome (Android)
  • Safari (OSX)
  • Safari (iOS)
  • Firefox
  • Firefox (Android)

- In many currency-related use cases, a minimal decimal precision of 2 digits is common. This way, large numbers get displayed with two padded zeroes (i.e. $1,000,000.00) while small numbers support added precision of up-to n digits ($0.89765412 if n=8)
- This functionality is not currently possible with this library due to fixedDecimalScale enforcing EXACTLY n digits of precision, while decimalScale provides a MAXIMUM number of digits
- In a future release (breaking change) we can probably remove `fixedDecimalScale` and use only `minDecimalScale` and `decimalScale` to clamp the bounds of precision and satisfy every use case
@s-yadav
Copy link
Owner

s-yadav commented Apr 29, 2023

@RayzorFlash Thanks for the PR.
what about we introduce two new props. minimumFractionDigits and maximumFractionDigits. This aligns with Intl.NumberFormat options.

And then we can mark decimal scale and fixedDecimalScale deprecated which we can remove on next major release.

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