mirror of
https://github.com/element-plus/element-plus.git
synced 2026-03-13 07:51:17 +08:00
feat(components): [input-number] warn when exceeds the safe integer (#19405)
This commit is contained in:
@@ -192,6 +192,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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user