From 29dd740c861a9a084704d900a27a653d42f831cd Mon Sep 17 00:00:00 2001 From: anion0278 Date: Wed, 17 Nov 2021 12:21:08 +0100 Subject: [PATCH] fix: exception during csv currency parsing --- Mapp.DataAccess/CsvLoader.cs | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/Mapp.DataAccess/CsvLoader.cs b/Mapp.DataAccess/CsvLoader.cs index e5e4d7d..5f3b042 100644 --- a/Mapp.DataAccess/CsvLoader.cs +++ b/Mapp.DataAccess/CsvLoader.cs @@ -12,7 +12,6 @@ public interface ICsvLoader { Dictionary LoadFixedCurrencyRates(); Dictionary LoadCountryVatRates(); - string ToInvariantFormat(string input); } public class CsvLoader : ICsvLoader @@ -70,8 +69,8 @@ private Dictionary ParseCurrencyRates(string downloadString, in var ratesDict = new Dictionary(); 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); } @@ -95,18 +94,13 @@ private Dictionary ParseVatRates(string downloadString) var ratesDict = new Dictionary(); 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 DownloadLatestCurrencyRates() //{