There is a question where I have to compute future investment value using the following method header:

for which the output is as example follow:Quote:

public static double futureInvestmentValue(double investmentAmount, double monthlyInterestRate, int years)

Years Future value

1 1093.80

2 1196.41

...

29 13467.25

30 14730.57

I notice that there should be 2 decimal places behind regardless of the decimal places are 0 or not(the zero should be display)

I have search on Internet and found that BigDecimal is correct way to deal with money. My snippet code as below.

Code:`for(int i = 1; i <= years; i++){`

System.out.println(i + "\t\t" + futureInvestmentValue(investmentAmount, monthlyInterestRate, i));

}

The problem i faced here is that BigDecimal cannot be return in double method, and thus I try to convert it to double usingCode:`public static double futureInvestmentValue(double investmentAmount, double monthlyInterestRate, int years){`

double futureInvestmentValue = investmentAmount * Math.pow(1 + monthlyInterestRate, years * 12);

BigDecimal newVal = new BigDecimal(futureInvestmentValue);

BigDecimal displayVal = newVal.setScale(2, RoundingMode.HALF_DOWN);

Double d = displayVal.doubleValue();

return d;

}

Double d = displayVal.doubleValue();

Although it managed to compile, but converting BigDecimal back to double again results in the 0 in decimal places not displayed.

How should I solve this problem?