mirror of
https://github.com/element-plus/element-plus.git
synced 2025-03-07 15:47:57 +08:00
feat(components): [input-number] warn when exceeds the safe integer
This commit is contained in:
parent
79c43db20e
commit
e80682d1b1
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user