При запуске программы расчета инвесторских кредитов моя программа выдает очень длинный вывод будущей стоимости владельца, содержащий букву «E». Я не уверен, что мои формулы неверны или я что-то неправильно закодировал, поскольку я новичок в Java.
import java.util.Scanner;
public class InvestorLoans {
public static void main(String [] args) {
Scanner input = new Scanner (System.in);
System.out.println("Please enter the amount invested: \n");
double investorAmount = input.nextDouble();
System.out.println("\n");
System.out.println("Please enter the current company valuation (in millions): \n");
double userValue = input.nextDouble();
System.out.println("\n");
double currentValue = userValue * 1000000;
System.out.println("Please enter the estimated rate of growth: \n");
double userRate = input.nextDouble();
System.out.println("\n");
double growthRate = userRate / 100;
System.out.println("Please enter the percentage of company given for investment: \n");
double userPercentage = input.nextDouble();
System.out.println("\n");
double investorPercentage = userPercentage / 100;
System.out.println("Please enter the number of investment years: \n");
double time = input.nextDouble();
System.out.println("\n");
double companyFutureValue = currentValue * Math.pow((1 + growthRate), time);
double investorFutureValue = investorPercentage * companyFutureValue;
double ownerFutureValue = companyFutureValue - (investorAmount + investorFutureValue);
System.out.println("The amount invested is: \t" + investorAmount);
System.out.println("The current valuation is: \t" + userValue + " million");
System.out.println("The growth rate is: \t" + userRate + "%");
System.out.println ("The investor percentage is: \t" + userPercentage + "%");
System.out.println ("The investment years is: \t" + time);
System.out.println("\n");
System.out.println(companyFutureValue);
System.out.println(investorFutureValue);
System.out.println("The owner future value is: \t" + ownerFutureValue);
}
}
При запуске программы я ввожу значения 2000000 (инвестированная сумма, 10 (оценка в миллионах), 60 (процент роста), 20 (процент инвестиций), 5 (годы инвестиций). ).
Я ожидал получить рациональное число с точностью до 2–3 десятичных знаков в качестве результата будущей стоимости владельца, но вместо этого получил 8,188608000000003E7.
Please enter the amount invested:
2000000
Please enter the current company valuation (in millions):
10
Please enter the estimated rate of growth:
60
Please enter the percentage of company given for investment:
20
Please enter the number of investment years:
5
The amount invested is: 2000000.0
The current company valuation is: 10.0 million.
The growth rate is: 60.0%.
The investor percentage is: 20.0%.
The investment years is: 5.0
The owner future value is: 8.188608000000003E7
Подробнее здесь: https://stackoverflow.com/questions/787 ... -that-long