0

Why does the code below give different results?! I am VERY shocked about this.

static void Main(string[] args)
{
    int myInt = (int)(5 * 1.4f);
    Console.WriteLine(myInt); //Outputs 6

    float myFloat = 5 * 1.4f;
    myInt = (int)myFloat;
    Console.WriteLine(myInt); //Outputs 7

    Console.ReadLine();
}

They should both give the result 7, but the first gives me 6. And 5 * 1.4f should be 7.

Assassinbeast
  • 1,207
  • 1
  • 17
  • 33

0 Answers0