Thursday, 9 March 2017

How to change string number to desired number decimal format



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
NumberFormat nf = NumberFormat.getCurrencyInstance(LocaleContextHolder.getLocale());
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