fix: input-number in step-strictly onChange bug (#6662)

Co-authored-by: xiaochenchen <xiaochen.chen@igg.com>
This commit is contained in:
Xc 2022-03-16 21:53:57 +08:00 committed by GitHub
parent 23d49c06c2
commit c6b69e217d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -193,6 +193,13 @@ export default defineComponent({
}
const setCurrentValue = (newVal: number | string) => {
const oldVal = data.currentValue
if (props.stepStrictly) {
const stepPrecision = getPrecision(props.step)
const precisionFactor = 10 ** stepPrecision
newVal =
(Math.round(newVal / props.step) * precisionFactor * props.step) /
precisionFactor
}
if (typeof newVal === 'number' && props.precision !== undefined) {
newVal = toPrecision(newVal, props.precision)
}