Friday, December 05, 2008

Try out

Try out this in C#

            double result = Convert.ToDouble(7) - 5.3;
            if (result == 1.7)
                Console.WriteLine("No Bug");
            else
                Console.WriteLine("WHAT!!!!!!!!");
            Console.ReadLine();
Test it and post me in comment what result did you get.

7 comments:

  1. Anonymous9:08 PM

    This comment has been removed by the author.

    ReplyDelete
  2. Anonymous9:11 PM

    Interesting, result has a rounding error which forces to prints 'WHAT!!!!!!!!'. Decimal data type solves the problem.

    double x = Convert.ToDouble(7);
    double y = Convert.ToDouble(5.3);
    Decimal result = Convert.ToDecimal(x - y);

    if (result == Convert.ToDecimal(1.7))
    Console.WriteLine("No Bug");
    else
    Console.WriteLine("WHAT!!!!!!!!");

    Console.ReadLine();

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. Mihai Stanimir4:09 PM

    Never compare floating point values for equality. Good books keep saying this and programmers keep ignoring it ;)

    ReplyDelete
  5. Never read it actually :$

    ReplyDelete
  6. Mihai Stanimir1:11 PM

    Hehe, there's still time ;)

    ReplyDelete
  7. Anonymous8:24 PM

    Erm, if you don't understand this then I don't think you should be blogging about programming.

    ReplyDelete