title: Java programming, decimals numbers
body: <p>This is a compound interest calculator, everything works fine excepts that i can't figured how to get my answer to have just 2 decimals, not a long number as right now. Please take a look at the codes and suggest if anything i should correct. Thank you very much.</p>
  
  <pre><code>class InvestmentProject{
  public double CompoundInterest(double InitialDeposit, double YearlyContribution, double InterestRate, int PeriodsInYr) {
  
  double RateInDecimal = InterestRate/100;
  double Value = YearlyContribution/RateInDecimal - YearlyContribution/(RateInDecimal * Math.pow(1 + RateInDecimal, PeriodsInYr));
  return (InitialDeposit + Value) * Math.pow(1 + RateInDecimal, PeriodsInYr);
  }
  }
  </code></pre>