Fix decimal conversion with precision

This commit is contained in:
Kenny Daniel 2024-05-12 19:52:15 -07:00
parent 76a0c99b60
commit fe7e19b2a4
No known key found for this signature in database
GPG Key ID: 90AB653A8CAD7E45
2 changed files with 30 additions and 28 deletions

@ -16,13 +16,15 @@ export function convert(data, schemaElement) {
return data.map(v => v && decoder.decode(v))
}
if (ctype === 'DECIMAL') {
const scaleFactor = schemaElement.scale ? Math.pow(10, schemaElement.scale) : 1
const scale = schemaElement.scale || 0
const precision = schemaElement.precision || 0
const factor = Math.pow(10, scale - precision)
if (typeof data[0] === 'number') {
return scaleFactor === 1 ? data : data.map(v => v * scaleFactor)
return factor === 1 ? data : data.map(v => v * factor)
} else if (typeof data[0] === 'bigint') {
return scaleFactor === 1 ? data : data.map(v => v * BigInt(scaleFactor))
return factor === 1 ? data : data.map(v => v * BigInt(factor))
} else {
return data.map(v => parseDecimal(v) * scaleFactor)
return data.map(v => parseDecimal(v) * factor)
}
}
if (ctype === 'DATE') {

@ -1,26 +1,26 @@
[
[ 10000 ],
[ 20000 ],
[ 30000 ],
[ 40000 ],
[ 50000 ],
[ 60000 ],
[ 70000 ],
[ 80000 ],
[ 90000 ],
[ 100000 ],
[ 110000 ],
[ 120000 ],
[ 130000 ],
[ 140000 ],
[ 150000 ],
[ 160000 ],
[ 170000 ],
[ 180000 ],
[ 190000 ],
[ 200000 ],
[ 210000 ],
[ 220000 ],
[ 230000 ],
[ 240000 ]
[ 1 ],
[ 2 ],
[ 3 ],
[ 4 ],
[ 5 ],
[ 6 ],
[ 7 ],
[ 8 ],
[ 9 ],
[ 10 ],
[ 11 ],
[ 12 ],
[ 13 ],
[ 14 ],
[ 15 ],
[ 16 ],
[ 17 ],
[ 18 ],
[ 19 ],
[ 20 ],
[ 21 ],
[ 22 ],
[ 23 ],
[ 24 ]
]