[PR #2799] [MERGED] Update regex for looselyParseAmount for 5-9 decimal places #4517

Closed
opened 2026-02-28 20:56:57 -06:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/actualbudget/actual/pull/2799
Author: @sreetamdas
Created: 5/25/2024
Status: Merged
Merged: 6/3/2024
Merged by: @youngcw

Base: masterHead: fix-decimal-parsing


📝 Commits (5)

  • 1d7d52b Update regex for looselyParseAmount for 5-9 decimal places
  • 426fec7 Add release note
  • 2d3c909 Update comment, add some more tests
  • 0c4cca5 Merge branch 'master' into fix-decimal-parsing
  • b169ffd Merge branch 'master' into fix-decimal-parsing

📊 Changes

3 files changed (+17 additions, -3 deletions)

View changed files

📝 packages/loot-core/src/shared/util.test.ts (+9 -1)
📝 packages/loot-core/src/shared/util.ts (+2 -2)
upcoming-release-notes/2799.md (+6 -0)

📄 Description

Update the regex to parse 5-9 decimal places, instead of just 5.


While trying to import transactions using a CSV file (that I download from my stock broker) where the amounts contain 6 decimal places, I encountered a bug where the amount was incorrectly parsed: 15.930000 as 15930000 😅

This is the code block that parses amounts when importing transactions (link):

function extractNumbers(v: string): string {
  // decimal is removed, 15.930000 ➡️ 15930000
  return v.replace(/[^0-9-]/g, "");
}

// look for a decimal marker, then look for either 5 or 1-2 decimal places.
// This avoids matching against 3 places which may not actually be decimal
const m = amount.match(/[.,]([^.,]{5}|[^.,]{1,2})$/);
if (!m || m.index === undefined || m.index === 0) {
  return safeNumber(parseFloat(extractNumbers(amount)));
}

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/actualbudget/actual/pull/2799 **Author:** [@sreetamdas](https://github.com/sreetamdas) **Created:** 5/25/2024 **Status:** ✅ Merged **Merged:** 6/3/2024 **Merged by:** [@youngcw](https://github.com/youngcw) **Base:** `master` ← **Head:** `fix-decimal-parsing` --- ### 📝 Commits (5) - [`1d7d52b`](https://github.com/actualbudget/actual/commit/1d7d52b95fe0f98f2e8c0db232bdbb78b09b5497) Update regex for `looselyParseAmount` for 5-9 decimal places - [`426fec7`](https://github.com/actualbudget/actual/commit/426fec777a8e4d615b77baf670cb2f3e1cac4048) Add release note - [`2d3c909`](https://github.com/actualbudget/actual/commit/2d3c909a1af9177159d6844914887677aeb0237b) Update comment, add some more tests - [`0c4cca5`](https://github.com/actualbudget/actual/commit/0c4cca56d825a420f5e09348778a6a1ab7d1727a) Merge branch 'master' into fix-decimal-parsing - [`b169ffd`](https://github.com/actualbudget/actual/commit/b169ffd77fcb4dbb26382dc7318f54b91af9edc2) Merge branch 'master' into fix-decimal-parsing ### 📊 Changes **3 files changed** (+17 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `packages/loot-core/src/shared/util.test.ts` (+9 -1) 📝 `packages/loot-core/src/shared/util.ts` (+2 -2) ➕ `upcoming-release-notes/2799.md` (+6 -0) </details> ### 📄 Description Update the regex to parse 5-9 decimal places, instead of just 5. --- While trying to import transactions using a CSV file (that I download from my stock broker) where the amounts contain 6 decimal places, I encountered a bug where the amount was incorrectly parsed: `15.930000` as `15930000` 😅 This is the code block that parses amounts when importing transactions ([link](https://github.com/actualbudget/actual/blob/b803731bc52dbf3628b2129c7881cebabd24488e/packages/loot-core/src/shared/util.ts#L404-L414)): ```ts function extractNumbers(v: string): string { // decimal is removed, 15.930000 ➡️ 15930000 return v.replace(/[^0-9-]/g, ""); } // look for a decimal marker, then look for either 5 or 1-2 decimal places. // This avoids matching against 3 places which may not actually be decimal const m = amount.match(/[.,]([^.,]{5}|[^.,]{1,2})$/); if (!m || m.index === undefined || m.index === 0) { return safeNumber(parseFloat(extractNumbers(amount))); } ``` --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-02-28 20:56:57 -06:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/actual#4517