Здача 6. Рибна борса от Simple Operations and Calculations - More Exercises
using System;
namespace _06.Fishland
{
class StartUp
{
static void Main(string[] args)
{
const double musselsPrice = 7.5;
double mackerelPrice = double.Parse(Console.ReadLine());
double spratPrice = double.Parse(Console.ReadLine());
double bonitoKg = double.Parse(Console.ReadLine());
double scadKg = double.Parse(Console.ReadLine());
int musselsKg = int.Parse(Console.ReadLine());
double bonitoPrice = mackerelPrice + (mackerelPrice * 0.6);
double scadPrice = spratPrice + (spratPrice * 0.8);
double totalAmount = (bonitoKg * bonitoPrice) + (scadKg * scadPrice) + (musselsKg * musselsPrice);
Console.WriteLine($"{totalAmount:d2}");
}
}
}
ми отпечатва на конзолата
6.90
4.20
1.5
2.5
1
Unhandled exception. System.FormatException: Format specifier was invalid.
at System.Number.GetFloatingPointMaxDigitsAndPrecision(Char fmt, Int32& precision, NumberFormatInfo info, Boolean& isSignificantDigits)
at System.Number.FormatDouble(ValueStringBuilder& sb, Double value, ReadOnlySpan`1 format, NumberFormatInfo info)
at System.Number.TryFormatDouble(Double value, ReadOnlySpan`1 format, NumberFormatInfo info, Span`1 destination, Int32& charsWritten)
at System.Double.TryFormat(Span`1 destination, Int32& charsWritten, ReadOnlySpan`1 format, IFormatProvider provider)
at System.Text.StringBuilder.AppendFormatHelper(IFormatProvider provider, String format, ParamsArray args)
at System.String.FormatHelper(IFormatProvider provider, String format, ParamsArray args)
at System.String.Format(String format, Object arg0)
at _06.Fishland.StartUp.Main(String[] args) in C:\Users\kstoyanov\source\repos\PBMoreSimpleOperationsExercises\06.Fishland\StartUp.cs:line 18
Ако сменя Console.WriteLine($"{totalAmount:f2}"); работи безупречно
Някой може ли да ми каже защо не ми позволява да използвам "d2"?