diff --git a/CHANGELOG.md b/CHANGELOG.md index 2bc678e39b..5c7ceefa35 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## v1.9.2 (2021-02-24) + +Changes: + +- Fix parsing balance for countries using space as separator + ## v1.9.1 (2021-02-23) Changes: diff --git a/app/build.gradle b/app/build.gradle index b24251fdb6..a7d9df8c65 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -18,8 +18,8 @@ android { applicationId "me.hackerchick.catima" minSdkVersion 19 targetSdkVersion 29 - versionCode 61 - versionName "1.9.1" + versionCode 62 + versionName "1.9.2" vectorDrawables.useSupportLibrary true } diff --git a/app/src/main/java/protect/card_locker/Utils.java b/app/src/main/java/protect/card_locker/Utils.java index a6ba670328..2878169653 100644 --- a/app/src/main/java/protect/card_locker/Utils.java +++ b/app/src/main/java/protect/card_locker/Utils.java @@ -125,13 +125,13 @@ static public Boolean currencyHasDecimals(Currency currency) { static public BigDecimal parseCurrency(String value, Boolean hasDecimals) throws NumberFormatException { // If there are no decimals expected, remove all separators before parsing if (!hasDecimals) { - value = value.replaceAll("\\.", "").replaceAll(",", ""); + value = value.replaceAll("[^0-9]", ""); return new BigDecimal(value); } // There are many ways users can write a currency, so we fix it up a bit - // 1. Replace all commas with dots - value = value.replace(',', '.'); + // 1. Replace all non-numbers with dots + value = value.replaceAll("[^0-9]", "."); // 2. Remove all but the last dot while (value.split("\\.").length > 2) { diff --git a/app/src/test/java/protect/card_locker/UtilsTest.java b/app/src/test/java/protect/card_locker/UtilsTest.java index f4df8773db..761633feb3 100644 --- a/app/src/test/java/protect/card_locker/UtilsTest.java +++ b/app/src/test/java/protect/card_locker/UtilsTest.java @@ -25,28 +25,37 @@ public void parseBalances() assertEquals("1", Utils.parseCurrency("1", true).toPlainString()); assertEquals("1.00", Utils.parseCurrency("1.00", true).toPlainString()); assertEquals("1.00", Utils.parseCurrency("1,00", true).toPlainString()); + assertEquals("1.00", Utils.parseCurrency("1 00", true).toPlainString()); assertEquals("25", Utils.parseCurrency("2.5", false).toPlainString()); assertEquals("25", Utils.parseCurrency("2,5", false).toPlainString()); + assertEquals("25", Utils.parseCurrency("2 5", false).toPlainString()); assertEquals("205", Utils.parseCurrency("2.05", false).toPlainString()); assertEquals("205", Utils.parseCurrency("2,05", false).toPlainString()); + assertEquals("205", Utils.parseCurrency("2 05", false).toPlainString()); assertEquals("2.5", Utils.parseCurrency("2.5", true).toPlainString()); assertEquals("2.5", Utils.parseCurrency("2,5", true).toPlainString()); + assertEquals("2.5", Utils.parseCurrency("2 5", true).toPlainString()); assertEquals("2.05", Utils.parseCurrency("2.05", true).toPlainString()); assertEquals("2.05", Utils.parseCurrency("2,05", true).toPlainString()); + assertEquals("2.05", Utils.parseCurrency("2 05", true).toPlainString()); assertEquals("2.50", Utils.parseCurrency("2.50", true).toPlainString()); assertEquals("2.50", Utils.parseCurrency("2,50", true).toPlainString()); + assertEquals("2.50", Utils.parseCurrency("2 50", true).toPlainString()); assertEquals("995", Utils.parseCurrency("9.95", false).toPlainString()); assertEquals("995", Utils.parseCurrency("9,95", false).toPlainString()); + assertEquals("995", Utils.parseCurrency("9 95", false).toPlainString()); assertEquals("9.95", Utils.parseCurrency("9.95", true).toPlainString()); assertEquals("9.95", Utils.parseCurrency("9,95", true).toPlainString()); + assertEquals("9.95", Utils.parseCurrency("9 95", true).toPlainString()); assertEquals("1234", Utils.parseCurrency("1234", false).toPlainString()); assertEquals("1234", Utils.parseCurrency("1.234", false).toPlainString()); assertEquals("1234", Utils.parseCurrency("1,234", false).toPlainString()); + assertEquals("1234", Utils.parseCurrency("1 234", false).toPlainString()); assertEquals("1234", Utils.parseCurrency("1234", true).toPlainString()); assertEquals("1234.00", Utils.parseCurrency("1234.00", true).toPlainString()); @@ -54,6 +63,10 @@ public void parseBalances() assertEquals("1234.00", Utils.parseCurrency("1.234,00", true).toPlainString()); assertEquals("1234.00", Utils.parseCurrency("1,234.00", true).toPlainString()); assertEquals("1234.00", Utils.parseCurrency("1,234,00", true).toPlainString()); + assertEquals("1234.00", Utils.parseCurrency("1 234,00", true).toPlainString()); + assertEquals("1234.00", Utils.parseCurrency("1 234,00", true).toPlainString()); + assertEquals("1234.00", Utils.parseCurrency("1 234 00", true).toPlainString()); + } @Test @@ -88,4 +101,4 @@ public void formatBalances() assertEquals("1,234", Utils.formatBalanceWithoutCurrencySymbol(new BigDecimal("1234.00"), null)); assertEquals("1,234.00", Utils.formatBalanceWithoutCurrencySymbol(new BigDecimal("1234.00"), euro)); } -} \ No newline at end of file +}