Here you can find the source of bigDecimalPrint(BigDecimal value)
public static String bigDecimalPrint(BigDecimal value) throws Exception
//package com.java2s; import java.math.BigDecimal; public class Main { public static String bigDecimalPrint(BigDecimal value) throws Exception { final int scale = 2; String bigDecString = null; StringBuffer sB = null;// www. j av a 2 s .c o m String dV = null; StringBuffer str = null; bigDecString = value.toString(); sB = new StringBuffer(bigDecString); /* sB.toString(); double d = Double.parseDouble(sB.toString()); d = roundAndScale(d, scale); dV = Double.toString(d); StringBuffer _sB = new StringBuffer(dV.toString()); for(int i=0; i<_sB.length(); i++ ){ try { if(_sB.charAt(i) == '.') { if((_sB.length() - i) <= scale ) { _sB.append('0'); str = new StringBuffer(_sB.toString()); _sB = str; } } } catch(Exception ex) { ex.printStackTrace(); } } */ /* * IN 99 - Wrong Amounts returned * 12/08/2003 E. Munyiri * Where amounts equal or exceed 10million, the value returned is in exponential * format which is not recognised by the presentation layer. * Hence the logic to perform the parseDouble and roundAndScale has been removed * and the string value of the Amount is being returned. */ boolean isDecimalPointFound = false; for (int i = sB.length() - 1; i >= 0; i--) { if (sB.charAt(i) == '.') { isDecimalPointFound = true; if ((sB.length() - i) == scale) { sB.append('0'); } break; } } if (!isDecimalPointFound) { /* the toString on the BigDecimal value does not print out the .00 where * the decimal digits are 0, therefore these are appended to the string value. */ sB.append(".00"); } return sB.toString(); } }