-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix a few number parsing issues #3044
Changes from 6 commits
926f0ef
bcc3c0a
a99dda7
1ae1552
60451f1
6d24f07
80a3b67
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -137,7 +137,7 @@ async function parseOFX( | |
errors, | ||
transactions: data.transactions.map(trans => { | ||
return { | ||
amount: Number(trans.amount), | ||
amount: trans.amount, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dont use the built in conversion, which cant handle other format types other than decimal comma. |
||
imported_id: trans.fitId, | ||
date: trans.date, | ||
payee_name: trans.name || (useMemoFallback ? trans.memo : null), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,8 @@ | |
expect(looselyParseAmount('3')).toBe(3); | ||
expect(looselyParseAmount('3.4')).toBe(3.4); | ||
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.45000')).toBe(3.45); | ||
expect(looselyParseAmount('3.450000')).toBe(3.45); | ||
|
@@ -24,6 +26,15 @@ | |
expect(looselyParseAmount('3,4500000')).toBe(3.45); | ||
expect(looselyParseAmount('3,45000000')).toBe(3.45); | ||
expect(looselyParseAmount('3,450000000')).toBe(3.45); | ||
expect(looselyParseAmount("3'456.78")).toBe(3456.78); | ||
jfdoming marked this conversation as resolved.
Show resolved
Hide resolved
|
||
expect(looselyParseAmount("3'456.78000")).toBe(3456.78); | ||
expect(looselyParseAmount('1,00,000.99')).toBe(100000.99); | ||
expect(looselyParseAmount('1,00,000.99000')).toBe(100000.99); | ||
}); | ||
|
||
test('looseParseAmount works with leading decimal characters', () => { | ||
expect(looselyParseAmount('.45')).toBe(0.45); | ||
expect(looselyParseAmount(',45')).toBe(0.45); | ||
}); | ||
|
||
test('looseParseAmount works with negative numbers', () => { | ||
|
@@ -42,6 +53,7 @@ | |
// `3_45_23` (it needs a decimal amount). This function should be | ||
// thought through more. | ||
expect(looselyParseAmount('3_45_23.10')).toBe(34523.1); | ||
expect(looselyParseAmount('(1 500.99)')).toBe(-1500.99); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just for fun to be sure that spaces parse right |
||
}); | ||
|
||
test('number formatting works with comma-dot format', () => { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -415,7 +415,7 @@ export function looselyParseAmount(amount: string) { | |
// Look for a decimal marker, then look for either 1-2 or 5-9 decimal places. | ||
// This avoids matching against 3 places which may not actually be decimal | ||
const m = amount.match(/[.,]([^.,]{5,9}|[^.,]{1,2})$/); | ||
if (!m || m.index === undefined || m.index === 0) { | ||
if (!m || m.index === undefined) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This may need some vetting. The reason for this is that the check I removed made it so a value like '.50' would return as $50. This will return the correct amount now even if there is no non-decimal digits. |
||
return safeNumber(parseFloat(extractNumbers(amount))); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
category: Bugfix | ||
authors: [youngcw,wdpk] | ||
--- | ||
|
||
Fix decimal comma parsing for ofx files |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test doesn't mean anything anymore since the file parser was returning a string for the value which would get converted later