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

rawValueDivisor causing unexpected behavior when the input value contains an exponent #778

Open
tbaart435 opened this issue Jan 8, 2024 · 2 comments
Labels

Comments

@tbaart435
Copy link

tbaart435 commented Jan 8, 2024

Current behavior

Using AutoNumeric with the 2 decimals options, on an input tag which has an initial value of, for example, 2.3e-10, the input correctly shows 0.00. However, when we also use the rawValueDivisor option to 100, then the input is initially filled with the value 2.3, even though 2.3e-10 * 100 is 2.3e-8, which is still 0.00 when rounded.

The moment you hover your mouse over the input, it immediately corrects itself and shows 0.00, as it should be.

Expected behavior

The rawValueDivisor option shouldn't cause wrong values to be shown in the input tag.

Steps to reproduce the problem

  1. Use autoNumeric version v4.10.2
  2. In the browser Edge version 120.0.2210.91
  3. On the Windows operating system
  4. Then instantiate the autoNumeric object with the following options:
new AutoNumeric(domElement, { decimalPlaces: 0, suffixText: '%', rawValueDivisor: 100 });
  1. Then the input tag is instantiated with a wrong value. Hovering over it will fix it.

Link to live example (CodePen)

@tbaart435 tbaart435 changed the title rawValueDivisor causing unexpected behavior when the input number contains an exponent rawValueDivisor causing unexpected behavior when the input value contains an exponent Jan 8, 2024
@AlexandreBonneau
Copy link
Member

Using 2.3e-8 works as expected (see that example). This might be a precision problem; will investigate.

@tbaart435
Copy link
Author

tbaart435 commented Jan 9, 2024

Cool, thanks :)

Setting the decimalPlaces to 15 shows the issue better than setting it 2 like I did in my example.

image

The one that shows 2.3% also has decimalPlaces set to 15. And indeed, 2.3e-8 does work fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants