Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

BigDecimal usage

 
Vernon Gibson
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I ran into an accuracy problem using 'float' so I've switched to BigDecimal.
I now have:
BigDecimal value1 = new BigDecimal(0);
BigDecimal value2 = new BigDecimal(0);
String strValue = new String("12345.67");
Question:
How do I get the contents of strValue into value1?
I've several configurations including:
value1 = BigDecimal(strValue);
value1 = BigDecimal.valueOf(BigDecimal(strValue));
Regards
Vernon Gibson
 
Carl Trusiak
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could just create it that way
String strValue = "12345.67";
BigDecimal value1 = new BigDecimal(strValue);
or if you want to continue with the code you have. add it to it.
value1 = value1.add(new BigDecimal(strValue));
Hope this helps
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic