Below code helps to change the string number to desired number decimal format
String str="00000180000000";
BigDecimal number = new BigDecimal(str).divide(new BigDecimal("100"));// assign correct value
BigDecimal number = new BigDecimal(str).divide(new BigDecimal("100"));// assign correct value
NumberFormat nf = NumberFormat.getCurrencyInstance(LocaleContextHolder.getLocale());
DecimalFormatSymbols decimalFormatSymbols = ((DecimalFormat) nf).getDecimalFormatSymbols();
decimalFormatSymbols.setCurrencySymbol("");
((DecimalFormat) nf).setDecimalFormatSymbols(decimalFormatSymbols);
DecimalFormatSymbols decimalFormatSymbols = ((DecimalFormat) nf).getDecimalFormatSymbols();
decimalFormatSymbols.setCurrencySymbol("");
((DecimalFormat) nf).setDecimalFormatSymbols(decimalFormatSymbols);
String formatedNumber = nf.format(number);
Result :
1,800,000.00
No comments:
Post a Comment