G Guest Jun 14, 2005 #1 655.5555-655 =0.555500000000052 (655.55-655)*100 =54.9999999999955 Visual C# 2003
S Stefan Simek Jun 14, 2005 #2 Amir said: 655.5555-655 =0.555500000000052 (655.55-655)*100 =54.9999999999955 Visual C# 2003 Click to expand... Because of floating point errors. Use decimal if you require precision math instead. See Jon Skeet's great article http://yoda.arachsys.com/csharp/floatingpoint.html for details HTH, Stefan
Amir said: 655.5555-655 =0.555500000000052 (655.55-655)*100 =54.9999999999955 Visual C# 2003 Click to expand... Because of floating point errors. Use decimal if you require precision math instead. See Jon Skeet's great article http://yoda.arachsys.com/csharp/floatingpoint.html for details HTH, Stefan
G Grzegorz Kaczor Jun 14, 2005 #3 Amir said: 655.5555-655 =0.555500000000052 (655.55-655)*100 =54.9999999999955 Visual C# 2003 Click to expand... This is not C# specific. And is typical . I don't think you can do anything about that. Try rounding to required precision. Regards, Grzegorz Kaczor
Amir said: 655.5555-655 =0.555500000000052 (655.55-655)*100 =54.9999999999955 Visual C# 2003 Click to expand... This is not C# specific. And is typical . I don't think you can do anything about that. Try rounding to required precision. Regards, Grzegorz Kaczor
P Peter van der Goes Jun 14, 2005 #4 Amir Parsa said: 655.5555-655 =0.555500000000052 (655.55-655)*100 =54.9999999999955 Visual C# 2003 Click to expand... As stated by the other responders, this is the result of real number approximation in a binary machine. Found in Java, C++, etc. as well as C#. Here are some articles that you may find interesting: http://www.math.grin.edu/~stone/courses/fundamentals/IEEE-reals.html http://www.prosperosoftware.co.uk/s.../uk/co/prosperosoftware/pspnum/PSPvFloat.html http://www.scit.wlv.ac.uk/cbook/chap4.float.html The Decimal type in the .NET Framework is your best choice for max precision without doing extra work.
Amir Parsa said: 655.5555-655 =0.555500000000052 (655.55-655)*100 =54.9999999999955 Visual C# 2003 Click to expand... As stated by the other responders, this is the result of real number approximation in a binary machine. Found in Java, C++, etc. as well as C#. Here are some articles that you may find interesting: http://www.math.grin.edu/~stone/courses/fundamentals/IEEE-reals.html http://www.prosperosoftware.co.uk/s.../uk/co/prosperosoftware/pspnum/PSPvFloat.html http://www.scit.wlv.ac.uk/cbook/chap4.float.html The Decimal type in the .NET Framework is your best choice for max precision without doing extra work.