C# basics - Difference between float, double and decimal

decimal values has better precision and should be used for financial operation but work slower than double, so double values should be used when performance is priority.
In general, c# floating points have following precisions:

  • float - 7 digits
  • double - 15-16 digits
  • decimal - 28-29 digits


See below example:
Output of that example is as follows:
As you can see output output of conditions for float and double values is True. It is because float has 7 digits precision and our float1 value is equal 1 in relation to 7 digits of precision. The same situation is for double value in terms of 15 digits precision.

0 comments:

Post a Comment

Powered by Blogger.

Sample Text

Sample Text

Sample text

Sample Text

Social Icons

Social Icons

Followers

Featured Posts