A newbie question

  • Thread starter Thread starter Uri Tidhar
  • Start date Start date
U

Uri Tidhar

Hello,

I've got a small and probably naive question.
I have two variables of data type double.
Let's say:
x == 4340999.99;
y == 4300000;

When you do x-y in Calc for example, you get: 40999.99
But when you do it in C# you get: 40999.990000000224

Huh? Why? How can I get the exact result without using Math.Round()?

Thanks :)
 
Hello Uri,

The Double type is in a sence inexact by definition due to the way the
floating point numbers are stored internally. If you want exact precision to
a certain number of digits after the decimal point, use the System.Decimal
class instead.
 
Back
Top