Meaningless Drivel is fun!
The moose likes Beginning Java and the fly likes BigDecimal usage Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "BigDecimal usage" Watch "BigDecimal usage" New topic

BigDecimal usage

Vernon Gibson
Ranch Hand

Joined: Dec 01, 2000
Posts: 35
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");
How do I get the contents of strValue into value1?
I've several configurations including:
value1 = BigDecimal(strValue);
value1 = BigDecimal.valueOf(BigDecimal(strValue));
Vernon Gibson
Carl Trusiak

Joined: Jun 13, 2000
Posts: 3340
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

I Hope This Helps
Carl Trusiak, SCJP2, SCWCD
I agree. Here's the link:
subject: BigDecimal usage
It's not a secret anymore!