feat(components): [input-number] warn when exceeds the safe integer

This commit is contained in:
btea 2024-12-25 21:52:02 +08:00
parent 79c43db20e
commit e80682d1b1

View File

@ -191,6 +191,20 @@ const getPrecision = (value: number | null | undefined) => {
}
const ensurePrecision = (val: number, coefficient: 1 | -1 = 1) => {
if (!isNumber(val)) return data.currentValue
if (val >= Number.MAX_SAFE_INTEGER && coefficient === 1) {
debugWarn(
'InputNumber',
'The value has reached the maximum safe integer limit.'
)
return val
} else if (val <= Number.MIN_SAFE_INTEGER && coefficient === -1) {
debugWarn(
'InputNumber',
'The value has reached the minimum safe integer limit.'
)
return val
}
// Solve the accuracy problem of JS decimal calculation by converting the value to integer.
return toPrecision(val + props.step * coefficient)
}