InputNumber: Storing the number internally as a number loses precision #5631
Labels
Status: Needs Triage
Issue will be reviewed by Core Team and a relevant label will be added as soon as possible
Describe the bug
It may not be immediately obvious, but storing the
InputNumber
value as a number and emitting it as such is a bad idea. Similarly, requiring themin
,max
, andstep
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.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
<InputNumber>
component to increment up and down by 0.1<input>
component to increment up and down by 0.1<InputNumber>
does not correctly step float values.Expected behavior
InputNumber
should do the following:modelValue
,max
,min
, andstep
.The text was updated successfully, but these errors were encountered: