The problem is your initial value - the float
is exactly 7 significant decimal places:
float f = 1056964.63f; Console.WriteLine(f);
So in reality the second example is unexpected.
Now the exact value in f
is 1056965.625, but the value set for all values ββfrom 1056964.563 to 1056964.687 is therefore not even the β.6β part is always correct. This is why the docs for System.Single
state:
By default, a single value contains only 7 decimal digits of precision, although no more than 9 digits are supported inside it.
Additional information is saved when you convert to double
, because it can save it without "interpreting" it at all - where to convert it to decimal form (either for printing or for type decimal
) through code that knows that it cannot "trust "these last two digits.
source share