diff --git a/packages/loot-core/src/shared/util.test.ts b/packages/loot-core/src/shared/util.test.ts index ea42f2532d684470127f99a1973330ffadde3d0b..eaee1ee844e4afbbf709f58c5b6463ea86ed7949 100644 --- a/packages/loot-core/src/shared/util.test.ts +++ b/packages/loot-core/src/shared/util.test.ts @@ -5,15 +5,16 @@ describe('utility functions', () => { expect(looselyParseAmount('3')).toBe(3); expect(looselyParseAmount('3.45')).toBe(3.45); - // Right now it doesn't actually parse an "amount", it just parses - // a number. An "amount" is a valid transaction amount, usually a - // number with 2 decimal places. - expect(looselyParseAmount('3.456')).toBe(3.456); + // Parsing is currently limited to 2 decimal places. + // Only <. ,> and 2 other chars counts as decimal places + // Proper parsing would include format settings, + // but currently we are format agnostic + expect(looselyParseAmount('3.456')).toBe(3456); }); test('looseParseAmount works with alternate formats', () => { expect(looselyParseAmount('3,45')).toBe(3.45); - expect(looselyParseAmount('3,456')).toBe(3.456); + expect(looselyParseAmount('3,456')).toBe(3456); }); test('looseParseAmount works with negative numbers', () => { diff --git a/packages/loot-core/src/shared/util.ts b/packages/loot-core/src/shared/util.ts index a670b775c4c9e2dd0398cccc80e1e46bed903ab0..91f39de604aa6f4e74fd8ce6d0b24ec37525ddc3 100644 --- a/packages/loot-core/src/shared/util.ts +++ b/packages/loot-core/src/shared/util.ts @@ -370,7 +370,7 @@ export function looselyParseAmount(amount: string) { amount = amount.replace('(', '-').replace(')', ''); } - const m = amount.match(/[.,][^.,]*$/); + const m = amount.match(/[.,][^.,]{1,2}$/); if (!m || m.index === undefined || m.index === 0) { return safeNumber(parseFloat(extractNumbers(amount))); } diff --git a/upcoming-release-notes/2399.md b/upcoming-release-notes/2399.md new file mode 100644 index 0000000000000000000000000000000000000000..f1d2598ed0cf04f9fd7c88f0ec4fd0ba604378f4 --- /dev/null +++ b/upcoming-release-notes/2399.md @@ -0,0 +1,6 @@ +--- +category: Bugfix +authors: [youngcw] +--- + +Only match 2 decimal places when parsing amounts for file import