1

I'm currently stuck trying the following.

I have managed to store two values as BigDecimals, I have also managed to divide these values and show the chosen amount of decimals.

Current fields:

BigDecimal latestPopulation, earliestPopulation, gip, divider;

Like so:

latestPopulation = new BigDecimal(aInterger.toString());
earliestPopulation = new BigDecimal(bInterger.toString());
divider = latestPopulation.divide(earliestPopulation, 10, RoundingMode.HALF_UP);

I then need to use the power of like so:

gip = divider.pow(1/cInterger);

However when I call System.out.println(gip); it shows the result with no decimal places. How do I define the number of decimal places I want?

Glitchezz
  • 353
  • 2
  • 7
  • 21
  • Have you looked in setting the precision like this? http://stackoverflow.com/questions/9482889/set-specific-precision-of-a-bigdecimal – jrad Aug 11 '14 at 20:08
  • @Rod_Algonquin gip is also a BigDecimal. Updated post. – Glitchezz Aug 11 '14 at 20:09
  • You're making it hard for people to answer by excluding your type definitions for the variables involved. From the code above, I have to investigate return types before I can determine what gip is. Also, this code is odd. Why are you converting an integer to a string for the BigDecimal constructor, when the constructor supports integers? At any rate, assuming gip is a BigDecimal, you want to use gip.toPlainString(). – Dan Aug 11 '14 at 20:13

1 Answers1

1
System.out.println(gip.toPlainString());
Marek Musielak
  • 26,832
  • 8
  • 72
  • 80
Dan
  • 2,733
  • 1
  • 17
  • 6
  • And to clarify, when you call System.out.println(gip), println will automatically perform gip.toString(). In this case, the toString isn't producing the output you want to see. – Dan Aug 11 '14 at 20:18