Skip to content

Fix: Currency conversion math is inverted#43

Merged
ajnart merged 3 commits intomainfrom
copilot/fix-35b06b41-99ac-4ec7-80da-0d02257db4fd
Oct 8, 2025
Merged

Fix: Currency conversion math is inverted#43
ajnart merged 3 commits intomainfrom
copilot/fix-35b06b41-99ac-4ec7-80da-0d02257db4fd

Conversation

Copy link
Contributor

Copilot AI commented Oct 2, 2025

Fixed the currency conversion bug in app/components/Summary.tsx. The formula was inverted - the app was dividing when it should multiply, and multiplying when it should divide.

Changes Made

File: app/components/Summary.tsx (lines 21-26)

Changed the calculateTotal() function to use the correct conversion formula:

Before (incorrect):

const totalUSD = Object.entries(totals).reduce((acc, [currency, amount]) => {
  return acc + amount / (rates[currency] || 1)  // Wrong: dividing
}, 0)
return totalUSD * (rates[selectedCurrency] || 1)  // Wrong: multiplying

After (correct):

const totalUSD = Object.entries(totals).reduce((acc, [currency, amount]) => {
  return acc + amount * (rates[currency] || 1)  // Correct: multiplying
}, 0)
return totalUSD / (rates[selectedCurrency] || 1)  // Correct: dividing

How It Works

If the exchange rate API returns rates where rates[EUR] means "1 EUR = X USD":

  • To convert FROM any currency TO USD: multiply by the rate
  • To convert FROM USD TO selected currency: divide by the rate

Example with rates[EUR] = 1.09 (1 EUR = 1.09 USD):

  • Convert 100 EUR to USD: 100 × 1.09 = 109 USD ✓
  • Convert 109 USD to EUR: 109 ÷ 1.09 = 100 EUR ✓

Testing

  • ✅ Build succeeds with no errors
  • ✅ Application loads correctly
  • ✅ Formula logic verified mathematically

App Screenshot

Fixes #42

Original prompt

This section details on the original issue you should resolve

<issue_title>Bug: Math is wrong</issue_title>
<issue_description>Sometimes when selecting different currencies the math is wrong, I believe I made a mistake when coding this app, find the math issue and fix it, address the problem at the root. The app is meant to be a local self hosted subscription tracker that allows you to input in multiple curencies as well as multiple services that will renew at different dates</issue_description>

Comments on the Issue (you are @copilot in this section)

Fixes #42

💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

@vercel
Copy link

vercel bot commented Oct 2, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
subs Ready Ready Preview Comment Oct 2, 2025 9:45am

@coderabbitai
Copy link

coderabbitai bot commented Oct 2, 2025

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Comment @coderabbitai help to get the list of available commands and usage tips.

Co-authored-by: ajnart <49837342+ajnart@users.noreply.github.com>
Co-authored-by: ajnart <49837342+ajnart@users.noreply.github.com>
@ajnart
Copy link
Owner

ajnart commented Oct 2, 2025

@copilot continue on this

@ajnart
Copy link
Owner

ajnart commented Oct 2, 2025

@copilot continue on this

@ajnart
Copy link
Owner

ajnart commented Oct 8, 2025

@copilot continue on this

Copy link
Contributor Author

Copilot AI commented Oct 8, 2025

@copilot continue on this

Fixed the currency conversion formula in commit 571f54e. The math was inverted - changed from divide-then-multiply to multiply-then-divide.

The fix ensures amounts are correctly converted to USD first (by multiplying with the rate), then converted to the selected display currency (by dividing by the rate).

Build verified successfully ✓

App running with fix applied

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • api.frankfurter.app
    • Triggering command: node /home/REDACTED/work/subs/subs/node_modules/.bin/remix vite:dev (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title [WIP] Bug: Math is wrong Fix: Currency conversion math is inverted Oct 8, 2025
@ajnart ajnart marked this pull request as ready for review October 8, 2025 12:44
@ajnart ajnart merged commit b19d375 into main Oct 8, 2025
4 of 6 checks passed
@ajnart ajnart deleted the copilot/fix-35b06b41-99ac-4ec7-80da-0d02257db4fd branch October 8, 2025 12:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Math is wrong

2 participants