Why do I get this Result in (655.55-655)*100 =54.9999999999955 ??

  • Thread starter Thread starter Guest
  • Start date Start date
Amir said:
655.5555-655 =0.555500000000052
(655.55-655)*100 =54.9999999999955
Visual C# 2003

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 Parsa said:
655.5555-655 =0.555500000000052
(655.55-655)*100 =54.9999999999955
Visual C# 2003

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.
 
Back
Top