Browse Source

Currency format fixes

master
Preyea Regmi 6 years ago
parent
commit
6d64f4722a
  1. 32
      app/src/main/java/com/gmeremit/online/gmeremittance_native/utils/Utils.java

32
app/src/main/java/com/gmeremit/online/gmeremittance_native/utils/Utils.java

@ -538,20 +538,40 @@ public class Utils {
return inputString.matches("^\\d+$"); 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) { public static String formatCurrency(String unformmatedCurrency) {
try { try {
unformmatedCurrency = unformmatedCurrency.replaceAll("\\.\\d*", "");
Long longval;
double decimalValue;
if (unformmatedCurrency.contains(",")) { if (unformmatedCurrency.contains(",")) {
unformmatedCurrency = unformmatedCurrency.replaceAll(",", ""); 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) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
return unformmatedCurrency; return unformmatedCurrency;
} }
} }

Loading…
Cancel
Save