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?