Why is floating point arithmetic in C# imprecise?

c#, floating-point

Solution

Floating point only has so many digits of precision. If you're seeing f1 == f2, it is because any difference requires more precision than a 32-bit float can represent.

I recommend reading What Every Computer Scientist Should Read About Floating Point

Problem

Why does the following program print what it prints? ``` class Program { static void Main(string[] args) { float f1 = 0.09f*100f; float f2 = 0.09f*99.999999f; Console.WriteLine(f1 > f2); } } ``` Output is ``` false ```

Original source

Related problems