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

All zero string decimals (e.g., '100.00') strips the '.00' and displays as '100.' #533

Closed
2 of 6 tasks
codypearce opened this issue May 7, 2021 · 3 comments
Closed
2 of 6 tasks
Assignees

Comments

@codypearce
Copy link

codypearce commented May 7, 2021

Describe the issue and the actual behavior

Values in the app I am working on are passed like this '100.00', with a decimalScale of 2, and isNumericString, like this.

<NumberFormat
        name={"AmountCents"}
        value={"100.00"}
        thousandSeparator
        prefix="$"
        decimalScale={2}
        isNumericString
      />

The result in the app
Screen Shot 2021-05-07 at 4 39 22 AM

Describe the expected behavior

Since it was passed in as 100.00 it should display as 100.00.

The changes in #501 appear to be the issue.

var floatValue = parseFloat("0.".concat(afterDecimal || '0'));
var floatValueStr = afterDecimal.length <= scale ? floatValue.toString() : floatValue.toFixed(scale);

floatValue is 0
afterDecimal.length is 2 and scale is 2
so floatValueStr returns floatValue.toString() which returns 0
However, floatValueStr should probably return 0.00

Provide a CodeSandbox link illustrating the issue

https://codesandbox.io/s/vigilant-shamir-dk4u9?file=/src/App.js

Provide steps to reproduce this issue

See codesandbox

Please check the browsers where the issue is seen

  • Chrome
  • Chrome (Android)
  • Safari (OSX)
  • Safari (iOS)
  • Firefox
  • Firefox (Android)
@nikhil-varma
Copy link
Collaborator

nikhil-varma commented May 11, 2021

Hey @codypearce Thanks for reporting this issue. We will investigate and shoot out a resolution soon. Keep an eye out for updates 🙂

@nikhil-varma nikhil-varma self-assigned this May 13, 2021
@nikhil-varma
Copy link
Collaborator

@codypearce Just a quick work around until the issue is being investigated. You can use the fixedDecimalScale prop to match the leading zeros. Here's a sample Codesandbox link: https://codesandbox.io/s/zealous-oskar-wjnqh

From the document for fixedDecimalScale

If true it add 0s to match given decimalScale

I will get back to you with an update on the issue resolution. Thank you for your patience.

nikhil-varma added a commit that referenced this issue Jun 8, 2021
- Add relevant test cases
@nikhil-varma nikhil-varma mentioned this issue Jun 8, 2021
6 tasks
nikhil-varma added a commit that referenced this issue Jun 9, 2021
@nikhil-varma
Copy link
Collaborator

@codypearce This issue is now fixed and released in v4.6.2

Closing this issue in light of the fix. Feel free to open/ask questions if required.

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