• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

BigDecimal usage

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic