При запуске программы расчета инвесторских кредитов моя программа выдает очень длинный вывод будущей стоимости владельца, содержащий букву «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
Почему мои выходные значения отображают букву E, хотя они не должны быть такими длинными? [дубликат] ⇐ JAVA
Программисты JAVA общаются здесь
1720071449
Anonymous
При запуске программы расчета инвесторских кредитов моя программа выдает очень длинный вывод будущей стоимости владельца, содержащий букву «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
Подробнее здесь: [url]https://stackoverflow.com/questions/78705197/why-are-my-output-values-displaying-e-when-they-shouldnt-be-that-long[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия