File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
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
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: BigDecimal usage
Similar Threads
Handling Multiple Submits
XML handler --> populate Hashmap
Convert String to BigDecimal
Class cast on Object Array
comparision between double and long