mirror of
https://github.com/actualbudget/actual.git
synced 2026-03-11 20:44:32 -05:00
* specify 2 decimal places in the csv amount parser * note * update tests * cleanup
This commit is contained in:
@@ -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', () => {
|
||||
|
||||
@@ -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)));
|
||||
}
|
||||
|
||||
6
upcoming-release-notes/2399.md
Normal file
6
upcoming-release-notes/2399.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
category: Bugfix
|
||||
authors: [youngcw]
|
||||
---
|
||||
|
||||
Only match 2 decimal places when parsing amounts for file import
|
||||
Reference in New Issue
Block a user