fix(import): remove commas from numbers (#3011)

This commit is contained in:
chenos 2023-11-10 10:00:21 +08:00 committed by GitHub
parent 4ed6d50400
commit 3d0b42e72e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 0 deletions

View File

@ -22,6 +22,12 @@ describe('number value parser', () => {
expect(parser.errors.length === 0).toBeTruthy(); expect(parser.errors.length === 0).toBeTruthy();
expectValue('22.5507%').toBe(0.225507); expectValue('22.5507%').toBe(0.225507);
expect(parser.errors.length === 0).toBeTruthy(); expect(parser.errors.length === 0).toBeTruthy();
expectValue('2,122,121,122').toBe(2122121122);
expect(parser.errors.length === 0).toBeTruthy();
expectValue('2,122,121,122.5507').toBe(2122121122.5507);
expect(parser.errors.length === 0).toBeTruthy();
expectValue('11,122.5507%').toBe(111.225507);
expect(parser.errors.length === 0).toBeTruthy();
}); });
it('should be null', () => { it('should be null', () => {

View File

@ -11,6 +11,7 @@ export class NumberValueParser extends BaseValueParser {
} else if (['n/a', '-'].includes(value.toLowerCase())) { } else if (['n/a', '-'].includes(value.toLowerCase())) {
this.value = null; this.value = null;
} else { } else {
value = value.replace(/,/g, '');
if (value.endsWith('%')) { if (value.endsWith('%')) {
value = percent2float(value); value = percent2float(value);
} else { } else {