Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

1. ## Present Value

```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?

2. ## 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.

3. ## 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.