Skip to content

fix: Keep Amount as float, format to 2 decimals at UI layer - #190

Merged
khanirfan18 merged 1 commit into
khanirfan18:mainfrom
TanCodeX:fix/amount-precision-handling
Jun 8, 2026
Merged

fix: Keep Amount as float, format to 2 decimals at UI layer#190
khanirfan18 merged 1 commit into
khanirfan18:mainfrom
TanCodeX:fix/amount-precision-handling

Conversation

@TanCodeX

@TanCodeX TanCodeX commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Summary

Closes #189

This PR resolves a precision issue caused by converting transaction amounts to strings too early in the data flow. Previously, transaction amounts were formatted using .toFixed(2) within displayTransactions, which converted numeric values into strings and required downstream components to repeatedly parse them back into numbers for calculations.

The updated implementation preserves transaction amounts as numeric values throughout state management and calculation logic, while applying formatting only at the UI layer.

Changes

AppContext

src/context/AppContext.jsx

  • Removed internal .toFixed(2) usage from displayTransactions.
  • Kept convertedAmt as a raw numeric value instead of converting it to a string.
  • Ensured transaction data remains numeric throughout processing and state updates.

UI Formatting

Moved decimal formatting to the rendering layer to preserve existing display behavior.

Updated the following components to format values with .toFixed(2) only when rendering:

  • src/pages/Transaction.jsx
  • src/pages/Dashboard.jsx
  • src/pages/Budgets.jsx
  • src/pages/Goals.jsx
  • src/components/CategoryBreakdown.jsx
  • src/components/InsightCards.jsx

Benefits

  • Prevents unnecessary number → string → number conversions.
  • Reduces the risk of floating-point precision issues during calculations.
  • Maintains consistent numeric types throughout application state.
  • Preserves existing UI behavior and currency formatting.
  • Improves separation of concerns between data processing and presentation.

Testing

  • Verified transaction amounts remain numeric after currency conversion.
  • Confirmed calculations in budgets, goals, dashboard metrics, and insights continue to produce expected results.
  • Confirmed all displayed monetary values retain two decimal places in the UI.
  • Verified no visual regressions in transaction, dashboard, budget, goal, category breakdown, or insight views.

@netlify

netlify Bot commented Jun 8, 2026

Copy link
Copy Markdown

👷 Deploy request for finnboard0 pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit b8a1d70

@netlify

netlify Bot commented Jun 8, 2026

Copy link
Copy Markdown

Deploy Preview for finnboard ready!

Name Link
🔨 Latest commit b8a1d70
🔍 Latest deploy log https://app.netlify.com/projects/finnboard/deploys/6a26580bb6c7ab0008f1f643
😎 Deploy Preview https://deploy-preview-190--finnboard.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@khanirfan18
khanirfan18 merged commit 3097921 into khanirfan18:main Jun 8, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: Amount Precision Handling by Avoiding Premature String Conversion

2 participants