locked
Operator '/' cannot be applied to operands of type 'decimal' and 'double RRS feed

  • Question

  • User-1272736690 posted
    static void Main(string[] args)
            {
                Console.WriteLine("Введiть цiну в Злотих :");
                decimal a;
                a = Convert.ToDecimal(Console.ReadLine());
                Console.WriteLine("Введiть курс Злотого :");
                decimal b; 
                b = Convert.ToDecimal(Console.ReadLine());
                Console.WriteLine((decimal)(a / 1.23) * b);
                Console.ReadKey();
                
            }

    Guys I`m new to C# and I need help, cannot solve this problem :(

    Wednesday, August 8, 2018 7:37 PM

Answers

  • User-82109136 posted

    Try using the suffix "m" as below:

    Console.WriteLine((decimal)(a / 1.23m) * b);

    This forces the literal to a decimal

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, August 8, 2018 8:04 PM

All replies

  • User-82109136 posted

    Try using the suffix "m" as below:

    Console.WriteLine((decimal)(a / 1.23m) * b);

    This forces the literal to a decimal

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, August 8, 2018 8:04 PM
  • User-1272736690 posted

    thanks a lot :)

    Wednesday, August 8, 2018 8:15 PM