mirror of
https://github.com/actualbudget/actual.git
synced 2026-04-28 10:33:02 -05:00
allow 4 decimal places in file imports (#3676)
* allow 4 decimals * note * fix comment * update test
This commit is contained in:
@@ -10,7 +10,8 @@ describe('utility functions', () => {
|
||||
expect(looselyParseAmount('3.45')).toBe(3.45);
|
||||
// cant tell if this next case should be decimal or different format
|
||||
// so we set as full numbers
|
||||
expect(looselyParseAmount('3.456')).toBe(3456);
|
||||
expect(looselyParseAmount('3.456')).toBe(3456); // the expected failing case
|
||||
expect(looselyParseAmount('3.4500')).toBe(3.45);
|
||||
expect(looselyParseAmount('3.45000')).toBe(3.45);
|
||||
expect(looselyParseAmount('3.450000')).toBe(3.45);
|
||||
expect(looselyParseAmount('3.4500000')).toBe(3.45);
|
||||
@@ -20,7 +21,8 @@ describe('utility functions', () => {
|
||||
|
||||
test('looseParseAmount works with alternate formats', () => {
|
||||
expect(looselyParseAmount('3,45')).toBe(3.45);
|
||||
expect(looselyParseAmount('3,456')).toBe(3456);
|
||||
expect(looselyParseAmount('3,456')).toBe(3456); //expected failing case
|
||||
expect(looselyParseAmount('3,4500')).toBe(3.45);
|
||||
expect(looselyParseAmount('3,45000')).toBe(3.45);
|
||||
expect(looselyParseAmount('3,450000')).toBe(3.45);
|
||||
expect(looselyParseAmount('3,4500000')).toBe(3.45);
|
||||
|
||||
@@ -427,9 +427,9 @@ export function looselyParseAmount(amount: string) {
|
||||
amount = amount.replace('(', '-').replace(')', '');
|
||||
}
|
||||
|
||||
// Look for a decimal marker, then look for either 1-2 or 5-9 decimal places.
|
||||
// Look for a decimal marker, then look for either 1-2 or 4-9 decimal places.
|
||||
// This avoids matching against 3 places which may not actually be decimal
|
||||
const m = amount.match(/[.,]([^.,]{5,9}|[^.,]{1,2})$/);
|
||||
const m = amount.match(/[.,]([^.,]{4,9}|[^.,]{1,2})$/);
|
||||
if (!m || m.index === undefined) {
|
||||
return safeNumber(parseFloat(extractNumbers(amount)));
|
||||
}
|
||||
|
||||
6
upcoming-release-notes/3676.md
Normal file
6
upcoming-release-notes/3676.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
category: Bugfix
|
||||
authors: [youngcw]
|
||||
---
|
||||
|
||||
Allow 4 decimal places in file import.
|
||||
Reference in New Issue
Block a user