Valerie Meunier

Valerie Meunier

  • NA
  • 693
  • 84.4k

how to get float result?

Jul 4 2021 12:40 PM

Hi

i divide two integers and i want to get a float result:

        int number1 =7;
        int number2 = 2
        float divide;

divide = number1 / number2

Console.Write(divide) =>gives 3

So i tried this: divide = (float)(number1 / number2); => gives 3

and this: Console.Write((foat)divide) => gives 3

and this: Consol.Write(Convert.ToSingle(divide)) => gives 3

How to get a float result (3.5)?

Thanks


Answers (3)