Valerie Meunier

Valerie Meunier

  • NA
  • 693
  • 83.2k

strange result when dividing two float numbers

Aug 23 2021 11:28 AM

Hi

When i input 5 as number and 2, as divider, i get  5/2 = 2,5 as result. That's ok.

But when i input 5 as number and 0 as divider, i get 5 / 0 = 8 ???

How come?

Thanks.

static void Main()
    {
        int number1, int number2;
        float div;

        Console.Write("Input number: ");
        number1 = Convert.ToInt32(Console.ReadLine());

        Console.Write("Input divider: ");
        number2 = Convert.ToInt32(Console.ReadLine());

        div= (float)number1 / (float)number2;
        Console.WriteLine("{0} / {1} = {2}", number1, number2, div);

}


Answers (2)