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

Intl.NumberFormat with fraction digits. input box <=> form state mismatch #825

Open
naseemkullah opened this issue Feb 13, 2024 · 2 comments

Comments

@naseemkullah
Copy link

When doing the same as https://s-yadav.github.io/react-number-format/docs/customization#intlnumberformat-based-formatting but with 2 maxFractionalDigits...

Also decimalScale is set to 2 and fixedDecimal is set to true.

Describe the issue and the actual / expected behavior

when user types in 3 decimal places, the input box UI rounds up (e.g. 1.239 shows up as 1.24 in the UI), ok great. But the state being set in the form is 1.239 - I don't want that, I just want 2 digits. i.e. what you see is what you get - no mismatch between UI and form state.

Provide a CodeSandbox link illustrating the issue

Provide steps to reproduce this issue

notable props

  const { size, ...rest } = useNumericFormat({
    decimalScale: 2,
    allowedDecimalSeparators: [',', '.'],
    fixedDecimalScale: true,
    valueIsNumericString: true,
  });

and try this format prop on a NumberFormatBase (along with the rest props above (there is a type mismatch with size, so its omitted)

     format={(value: string) => {
                        if (!value) return '';
                 

                        return Intl.NumberFormat(locale, {
                          style: 'currency',
                          currency,
                          maximumFractionDigits: 2,
                        }).format(Number(value));
                      }}
@akhilmannam
Copy link

Can you provide a sandbox link describing your issue?

@s-yadav
Copy link
Owner

s-yadav commented Feb 25, 2024

Yes, please include Code sandbox to demonstrate the issue, most likely onValueChange is not handled correctly.

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

3 participants