I have a string that shows a number with a comma separator like this:
DecimalFormat formatter = new DecimalFormat("#,###.000000");
String toDouble=formatter.format(amount);
Now I want to remove commas in BO class to do arithmetic operations. I used this format:
StrCash_price_deal = StrCash_price_deal.replace(",", "");
double d = Double.valueOf(StrCash_price_deal.trim()).doubleValue();
but it changes the value to zero!!!
my technology is struts2
You have a
DecimalFormatwhich you’re using to format the value. Use the same object to parse the value, instead of usingDouble.valueOf.Additionally:
doublefor currency values; useBigDecimalwhich will reduce the surprises you get when it comes to “inaccurate” arithmeticStrCash_price_dealis horrible in both casing and underscore-ness