From a99183cc7c2935757f52028a729be0ca3838a745 Mon Sep 17 00:00:00 2001 From: Tihomir Tonov Date: Tue, 21 Jul 2020 17:38:21 +0300 Subject: [PATCH 1/2] Fix android number format It seems that the currency should be set on the DecimalFormatSymbols instance before setting it to the NumberFormat instance in order to display proper currency. --- src/nativescript-intl.android.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/nativescript-intl.android.ts b/src/nativescript-intl.android.ts index 73f7942..37ca383 100644 --- a/src/nativescript-intl.android.ts +++ b/src/nativescript-intl.android.ts @@ -160,6 +160,11 @@ export class NumberFormat extends commonNumberFormat { let decimalFormatSymbols = locale ? new java.text.DecimalFormatSymbols(getNativeLocale(locale)) : new java.text.DecimalFormatSymbols(); + + if (options.currency !== void 0) { + decimalFormatSymbols.setCurrency(java.util.Currency.getInstance(options.currency)); + } + numberFormat.setDecimalFormatSymbols(decimalFormatSymbols); if (options && (options.style.toLowerCase() === "currency" && options.currencyDisplay === "code")) { @@ -170,10 +175,6 @@ export class NumberFormat extends commonNumberFormat { numberFormat = new java.text.DecimalFormat(currrentPattern); numberFormat.setDecimalFormatSymbols(decimalFormatSymbols); } - - if (options.currency !== void 0) { - decimalFormatSymbols.setCurrency(java.util.Currency.getInstance(options.currency)); - } } return numberFormat.format(value); From 3a6fa4bbf1e300f0a44ca5ba3f16c1dc91cc93d0 Mon Sep 17 00:00:00 2001 From: Tihomir Tonov Date: Wed, 12 Aug 2020 22:33:49 +0300 Subject: [PATCH 2/2] Check if the options is not null Co-authored-by: hiperbou --- src/nativescript-intl.android.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nativescript-intl.android.ts b/src/nativescript-intl.android.ts index 37ca383..7ee8ee5 100644 --- a/src/nativescript-intl.android.ts +++ b/src/nativescript-intl.android.ts @@ -161,7 +161,7 @@ export class NumberFormat extends commonNumberFormat { new java.text.DecimalFormatSymbols(getNativeLocale(locale)) : new java.text.DecimalFormatSymbols(); - if (options.currency !== void 0) { + if (options && options.currency !== void 0) { decimalFormatSymbols.setCurrency(java.util.Currency.getInstance(options.currency)); }