# Present Value

• April 3rd, 2014, 09:21 PM
rosiems95
Present Value
Code Java:

```import java.util.Scanner; import java.text.DecimalFormat;   public class PresentValue { public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); DecimalFormat num = new DecimalFormat("#,###.00"); double present = 0.0, annualRate = 0.0, future = 0.0, numberOfYears = 0.0;   System.out.print("Enter the future value: "); future = keyboard.nextDouble();   System.out.print("Enter annual interest rate (in decimal point, not percent): "); annualRate = keyboard.nextDouble();   System.out.print("Enter the number of years: "); numberOfYears = keyboard.nextDouble();   present = presentValue(future, present, annualRate, numberOfYears); System.out.print("Present value must be: \$" + num.format(present)); } public static double presentValue(double f, double p, double r, double n) { p = f/Math.pow(1 + r, n); return p; } }```

If the user were to enter 2.5 for the annual interest rate, how can I make sure it changes it to .025 instead of having to ask the user to enter in decimals and not percent?
• April 4th, 2014, 12:32 AM
dicdic
Re: Present Value
this is a Math question. Try to open you math books in grade school, or try to do an internet search about rates/percentage.
• April 4th, 2014, 04:57 AM
GregBrannon
Re: Present Value
Or, it's an input validation/modification question. Determine the scale of the value input by the user and modify it appropriately for the equation being used - and that's back to the math question.