Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -702,10 +702,26 @@ function round2 (value) {
|
||||
}
|
||||
|
||||
function parseNumber (val) {
|
||||
const normalized = String(val ?? '')
|
||||
.replace(/\s/g, '')
|
||||
.replace(/\./g, '')
|
||||
.replace(',', '.')
|
||||
if (typeof val === 'number') return Number.isFinite(val) ? val : 0
|
||||
const text = String(val ?? '').trim().replace(/\s/g, '')
|
||||
if (!text) return 0
|
||||
|
||||
const lastComma = text.lastIndexOf(',')
|
||||
const lastDot = text.lastIndexOf('.')
|
||||
let normalized = text
|
||||
|
||||
if (lastComma >= 0 && lastDot >= 0) {
|
||||
if (lastComma > lastDot) {
|
||||
normalized = text.replace(/\./g, '').replace(',', '.')
|
||||
} else {
|
||||
normalized = text.replace(/,/g, '')
|
||||
}
|
||||
} else if (lastComma >= 0) {
|
||||
normalized = text.replace(/\./g, '').replace(',', '.')
|
||||
} else {
|
||||
normalized = text.replace(/,/g, '')
|
||||
}
|
||||
|
||||
const n = Number(normalized)
|
||||
return Number.isFinite(n) ? n : 0
|
||||
}
|
||||
@@ -713,11 +729,7 @@ function parseNumber (val) {
|
||||
function parseNullableNumber (val) {
|
||||
const text = String(val ?? '').trim()
|
||||
if (!text) return null
|
||||
const normalized = text
|
||||
.replace(/\s/g, '')
|
||||
.replace(/\./g, '')
|
||||
.replace(',', '.')
|
||||
const n = Number(normalized)
|
||||
const n = parseNumber(text)
|
||||
return Number.isFinite(n) ? n : null
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user