fix: parse decimal money values without scale errors
This commit is contained in:
@@ -4,13 +4,15 @@
|
||||
* ilanları) analizler otomatik zenginleşir.
|
||||
*/
|
||||
|
||||
// "22.800,00 TRY" / "1.234.567,89 TL" gibi metinleri sayıya çevir
|
||||
// "22.800,00 TRY" / "1.234.567,89 TL" / "12.50 TL" gibi metinleri sayıya çevir
|
||||
export function parseTL(v) {
|
||||
if (v == null) return null;
|
||||
if (typeof v === 'number') return isFinite(v) ? v : null;
|
||||
const s = String(v).replace(/[^\d.,]/g, '');
|
||||
if (!s) return null;
|
||||
const norm = s.replace(/\./g, '').replace(',', '.');
|
||||
const norm = s.includes(',')
|
||||
? s.replace(/\./g, '').replace(',', '.')
|
||||
: /^(?:\d+\.\d{3})+$/.test(s) ? s.replace(/\./g, '') : s;
|
||||
const n = parseFloat(norm);
|
||||
return isFinite(n) ? n : null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user