Q:

Why am I getting the wrong result when using float?

Possible Duplicates:
Why is (double)0.6f > (double)(6/10f)?
Why is floating point arithmetic in C# imprecise? 

I have the following code in C#:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace StackOverflow
{
    class Program
    {
        static void Main(string[] args)
        {
            float num1 = 17.03F;
            float num2 = 17F;
            float result = num1 - num2;
            Console.WriteLine(result);
        }
    }
}

The code works fine but I am not getting the expected result. Can someone explain why this is happening?

A:

I guess you are refering to deviations cause by Floating point arithmetics. You can read about in in the provided link.
If you really need to make the calculation 100% accurate, you can use decimal instead of float.

