profileShare

rasmusjy / splitapp-backend-modular-monolith

Read-only snapshot

No repository description.

main default branch 418 files Expires Sep 13, 2026, 9:06 AM
CurrencyConverter.cs 754 bytes
1 namespace SplitApp.Modules.Expenses.Application;
2
3 public static class CurrencyConverter
4 {
5 private static readonly Dictionary<string, decimal> RatesToEur = new()
6 {
7 { "EUR", 1.0m },
8 { "USD", 0.92m },
9 { "GBP", 1.16m },
10 { "SEK", 0.087m },
11 { "NOK", 0.086m },
12 };
13
14 public static decimal Convert(decimal amount, string fromCurrencyCode, string toCurrencyCode)
15 {
16 if (fromCurrencyCode == toCurrencyCode) return amount;
17 if (!RatesToEur.TryGetValue(fromCurrencyCode, out var fromRate)) return amount;
18 if (!RatesToEur.TryGetValue(toCurrencyCode, out var toRate)) return amount;
19 var amountInEur = amount * fromRate;
20 return Math.Round(amountInEur / toRate, 2);
21 }
22 }
23