Skip to content

Commit

Permalink
fix(comp:input-number): decimal precision calculation error (#688)
Browse files Browse the repository at this point in the history
  • Loading branch information
imguolao committed Dec 30, 2021
1 parent 8f4eec0 commit d863ad0
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion packages/components/input-number/demo/Precision.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<template>
<IxInputNumber v-model:value="value" :max="10" :min="1" :precision="2" @change="handleChange"></IxInputNumber>
<IxInputNumber v-model:value="value" :max="10" :min="1" :precision="2" :step="0.01" @change="handleChange">
</IxInputNumber>
</template>

<script setup lang="ts">
Expand Down
2 changes: 1 addition & 1 deletion packages/components/input-number/src/useInputNumber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export function useInputNumber(props: InputNumberProps, config: InputNumberConfi
let newVal = step
if (typeof value === 'number' && !Number.isNaN(value)) {
// Use the toFixed func to ensure numerical accuracy.
newVal = parseFloat(value.toFixed(precision.value)) + step
newVal = parseFloat((value + step).toFixed(precision.value))
}

return Math.max(props.min, Math.min(props.max, newVal))
Expand Down

0 comments on commit d863ad0

Please sign in to comment.