Hey guys been working on a java Program. I am having a problem with my percent rounding up to 7% instead displaying 6.5% any ideas here is my Program.
import javax.swing.JOptionPane;
import java.math.*;
import java.text.NumberFormat;
public class Week_three_number_eleven {
public static void main(String[] args) {
String Investment = JOptionPane.showInputDialog(null,"Please enter the amount you would like to invest");
String IntrestRate = JOptionPane.showInputDialog(null,"Now please enter you desired intrest rate(Example .065 = 6.5%");
double Investment2 = Double.parseDouble(Investment);
double IntrestRate2 = Double.parseDouble(IntrestRate);
NumberFormat percentFormat = NumberFormat.getPercentInstance();
JOptionPane.showMessageDialog(null,"You choose $"+Investment+".00 at the intrest rate of " + percentFormat.format(IntrestRate2));
double ABS_Future5;
double ABS_Future10;
double ABS_Future20;
double FUTURE5 = Investment2 * Math.pow(1 + IntrestRate2,5.0);
double FUTURE10 = Investment2 * Math.pow(1 + IntrestRate2,10.0);
double FUTURE20 = Investment2 * Math.pow(1 + IntrestRate2,20.0);
ABS_Future5 = Math.round(FUTURE5);
ABS_Future10 = Math.round(FUTURE10);
ABS_Future20 = Math.round(FUTURE20);
JOptionPane.showMessageDialog(null,"Your investment in 5 years will be $"+ABS_Future5);
JOptionPane.showMessageDialog(null,"Your investment in 10 years will be $"+ABS_Future10);
JOptionPane.showMessageDialog(null,"Your investment in 20 years will be $"+ABS_Future20);
}
}
AT this point LINE 14 (JOptionPane.showMessageDialog(null,"You choose $"+Investment+".00 at the intrest rate of " + percentFormat.format(IntrestRate2));)
it is suppose to display the percent the user put in but it rounds it up on the viewing screen, im guessing it is an easy fix but i just cant see it.
Thanks! hope someone knows!