Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
String to bigdecimal
02-28-2008, 09:13 PM
Post: #1
String to bigdecimal
How can I convert a String like '$100,00.00' to BigDecimal
Find all posts by this user
Quote this message in a reply
02-28-2008, 09:35 PM
Post: #2
RE: String to bigdecimal
Try the following code.

[java]
String str = "$100,00.00";
str = str.replace('$',' ');
str = str.replaceAll(",","");
str = str.replace(".", "");
str = str.trim();

BigDecimal dec = new BigDecimal(str);
System.out.println(dec);
[/java]
Find all posts by this user
Quote this message in a reply
02-28-2008, 09:46 PM
Post: #3
RE: String to bigdecimal
Use DecimalFormat class for this purpose.

[java]
String str = "$100,00,00.00";
DecimalFormat format = new DecimalFormat("$0,0.00");
double value =format.parse(str).doubleValue();
BigDecimal dec = new BigDecimal(value);
[/java]
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump: