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

InputNumber: Storing the number internally as a number loses precision #5631

Open
matthew-dean opened this issue Apr 22, 2024 · 0 comments
Open
Labels
Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible

Comments

@matthew-dean
Copy link

Describe the bug

It may not be immediately obvious, but storing theInputNumber value as a number and emitting it as such is a bad idea. Similarly, requiring the min, max, and step values to be numbers is also a bad idea, just because of how JavaScript works, and this causes loss of precision and unpredictable functionality.

What the component appears to be doing, for example, when using step value of 0.1, is adding the number 0.1 to the current number value. In JavaScript, because floats have imprecise precision, this will add something close to 0.1 but not exactly 0.1.

Compare this to the html <input>. It will always step consistently, whereas PrimeVue's <InputNumber> will not.

Screenshot 2024-04-22 at 10 42 17 AM Screenshot 2024-04-22 at 10 42 26 AM

Reproducer

https://stackblitz.com/edit/primevue-create-vue-typescript-issue-template-obdp4u?file=src%2FApp.vue

PrimeVue version

3.47.2

Vue version

3.x

Language

TypeScript

Build / Runtime

Vue CLI App

Browser(s)

Chrome 124

Steps to reproduce the behavior

  1. Go to the Stackblitz
  2. Use the incrementing arrows on the <InputNumber> component to increment up and down by 0.1
  3. Use the incrementing arrows on the <input> component to increment up and down by 0.1
  4. Observe that <InputNumber> does not correctly step float values.

Expected behavior

InputNumber should do the following:

  1. Allow numeric strings to be assigned to modelValue, max, min, and step.
  2. Increment numbers when stepping using a decimal precision library. Consider: https://www.npmjs.com/package/big.js
@matthew-dean matthew-dean added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Apr 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible
Projects
None yet
Development

No branches or pull requests

1 participant