Skip to content

Commit

Permalink
fix: exception during csv currency parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
anion0278 committed Nov 17, 2021
1 parent ae7c9f5 commit 29dd740
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions Mapp.DataAccess/CsvLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ public interface ICsvLoader
{
Dictionary<string, decimal> LoadFixedCurrencyRates();
Dictionary<string, decimal> LoadCountryVatRates();
string ToInvariantFormat(string input);
}

public class CsvLoader : ICsvLoader
Expand Down Expand Up @@ -70,8 +69,8 @@ private Dictionary<string, decimal> ParseCurrencyRates(string downloadString, in
var ratesDict = new Dictionary<string, decimal>();
for (int index = skipLines; index < strArrayList.Count; ++index)
{
decimal num = decimal.Parse(ToInvariantFormat(strArrayList[index][skipColumns + 2])) /
decimal.Parse(ToInvariantFormat(strArrayList[index][skipColumns]));
decimal num = decimal.Parse(strArrayList[index][skipColumns + 2], CultureInfo.InvariantCulture) /
decimal.Parse(strArrayList[index][skipColumns], CultureInfo.InvariantCulture);
ratesDict.Add(strArrayList[index][skipColumns + 1], num);
}

Expand All @@ -95,18 +94,13 @@ private Dictionary<string, decimal> ParseVatRates(string downloadString)
var ratesDict = new Dictionary<string, decimal>();
for (int index = 0; index < strArrayList.Count; ++index)
{
decimal vat = decimal.Parse(ToInvariantFormat(strArrayList[index][1])) / (decimal) 100.0;
decimal vat = decimal.Parse(strArrayList[index][1], CultureInfo.InvariantCulture) / (decimal) 100.0;
ratesDict.Add(strArrayList[index][0], vat);
}

return ratesDict;
}

public string ToInvariantFormat(string input)
{
return input.Replace(",", CultureInfo.InvariantCulture.NumberFormat.NumberDecimalSeparator);
}


//private Dictionary<string, decimal> DownloadLatestCurrencyRates()
//{
Expand Down

0 comments on commit 29dd740

Please sign in to comment.