Hi I’d like know how to format BigDecimal representing numbers,percents,moneys,integers to String in Locales and from String back to BigDecimal. I’m using DecimalFormat which is powerful, but I’m not sure how to use conversion to exact type in default user locales. I first time use this:
DecimalFormat.getCurrencyInstance().format( obj );
DecimalFormat.getCurrencyInstance().parse( source );
But with large numbers its misrepresents their value. So i find something and get this:
DecimalFormat decimalFormat = new DecimalFormat();
decimalFormat.setParseBigDecimal( true );
BigDecimal bd = ( BigDecimal ) decimalFormat.parse( value );
But how to combine these thinks. I probably need set to DecimalFormat some pattern which is used in NumberFormat.get???instance(), but I don’t know how and if isn’t get some strange behavior.
So Please someone who has experience with this can you help me? Thanks Pavel
I think your best bet is to assume that
getCurrencyInstace()returns aDecimalFormat, which it probably does in all of the “important” locales. To be safe you could employinstanceof:In our application we basically do the same for something different where you’d need
SimpleDateFormat, but only haveDateFormatin general case.