jQuery in Action, 2nd edition*
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 Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "BigDecimal usage" Watch "BigDecimal usage" New topic
Author

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");
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

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
 
wood burning stoves
 
subject: BigDecimal usage
 
Similar Threads
Convert String to BigDecimal
Class cast on Object Array
comparision between double and long
Handling Multiple Submits
XML handler --> populate Hashmap