C# (4): double minus double giving precision problems

Posted by thermal7 on Stack Overflow See other posts from Stack Overflow or by thermal7
Published on 2010-04-30T02:09:41Z Indexed on 2010/04/30 2:17 UTC
Read the original article Hit count: 537

Filed under:
|
|

I have come across a precision issue with double in .NET I thought this only applied to floats but now I see that double is a float.

double test = 278.97 - 90.46;
Debug.WriteLine(test) //188.51000000000005

//correct answer is 188.51

What is the correct way to handle this? Round? Lop off the unneeded decimal places?

© Stack Overflow or respective owner

Related posts about c#

Related posts about double