Which type provides an accurate representation of a float value?

  • one
    And what is the "accurate representation"? Formalize. Otherwise, the exact answer is impossible to give. - VladD

4 answers 4

The exact representation in C # is provided by the decimal type - 28–29 significant digits.

There is no absolutely exact representation of a floating-point number in C #, since it would require an infinite amount of memory (at least for irrational numbers).

    C # does not have this type. All types have limited accuracy, except for the class BigInteger .
    The latter can be adapted for storing floating-point numbers if the decimal point position is also separately stored in a number.

    However, I dare say that not even all non-periodic decimal numbers provide an accurate representation. So, for example, the number 1/3 cannot have an exact representation in the form of a non-periodic decimal fraction.

      Type decimal . Unlike double, it is stored in decimal form, so it has no rounding errors ... But from its minuses there is a smaller range of values

        The decimal type, often used in banking transactions, has the largest number of decimal numbers (after BigInteger as indicated by @Dmitry) a link to the example https://dotnetfiddle.net/eEcj0r