O'Reilly logo
  • Adil Mammadov thinks this is interesting:

Real Number Rounding Errors

float and double internally represent numbers in base 2. For this reason, only numbers expressible in base 2 are represented precisely. Practically, this means most literals with a fractional component (which are in base 10) will not be represented precisely. For example:

float tenth = 0.1f;                       // Not quite 0.1
float one   = 1f;
Console.WriteLine (one - tenth * 10f);    // −1.490116E-08

This is why <...


Cover of C# 5.0 in a Nutshell, 5th Edition


Real numbers are not precise