From 6d64f4722a5b7d81921c6945cf0a76a22a803ed8 Mon Sep 17 00:00:00 2001 From: Preyea Regmi Date: Sat, 6 Oct 2018 13:38:43 +0545 Subject: [PATCH] Currency format fixes --- .../gmeremittance_native/utils/Utils.java | 32 +++++++++++++++---- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/gmeremit/online/gmeremittance_native/utils/Utils.java b/app/src/main/java/com/gmeremit/online/gmeremittance_native/utils/Utils.java index 28e313a3..d1f1053c 100644 --- a/app/src/main/java/com/gmeremit/online/gmeremittance_native/utils/Utils.java +++ b/app/src/main/java/com/gmeremit/online/gmeremittance_native/utils/Utils.java @@ -538,20 +538,40 @@ public class Utils { return inputString.matches("^\\d+$"); } +// public static String formatCurrency(String unformmatedCurrency) { +// try { +// unformmatedCurrency = unformmatedCurrency.replaceAll("\\.\\d*", ""); +// Long longval; +// if (unformmatedCurrency.contains(",")) { +// unformmatedCurrency = unformmatedCurrency.replaceAll(",", ""); +// } +// longval = Long.parseLong(unformmatedCurrency); +// +// DecimalFormat formatter = (DecimalFormat) NumberFormat.getInstance(Locale.US); +// formatter.applyPattern("#,###,###,###"); +// return formatter.format(longval); +// } catch (Exception e) { +// e.printStackTrace(); +// return unformmatedCurrency; +// } +// } + public static String formatCurrency(String unformmatedCurrency) { try { - unformmatedCurrency = unformmatedCurrency.replaceAll("\\.\\d*", ""); - Long longval; + double decimalValue; if (unformmatedCurrency.contains(",")) { unformmatedCurrency = unformmatedCurrency.replaceAll(",", ""); } - longval = Long.parseLong(unformmatedCurrency); + decimalValue = Double.parseDouble(unformmatedCurrency); + + DecimalFormat formatter = new DecimalFormat("#,###,###.##"); + + String temp= formatter.format(decimalValue); + return temp; - DecimalFormat formatter = (DecimalFormat) NumberFormat.getInstance(Locale.US); - formatter.applyPattern("#,###,###,###"); - return formatter.format(longval); } catch (Exception e) { e.printStackTrace(); + return unformmatedCurrency; } }