The precision of float
type implies this limitation. You can use double
type instead.
float
type in C# conforms to the IEEE 754-2008 binary32 format (Single-precision floating-point format)
From Wikipedia:
The IEEE 754 standard specifies a binary32 as having:
- Sign bit: 1 bit
- Exponent width: 8 bits
- Significand precision: 24 (23 explicitly stored)
This gives from 6 to 9 significant decimal digits precision (if a
decimal string with at most 6 significant decimal is converted to IEEE
754 single precision and then converted back to the same number of
significant decimal, then the final string should match the original;
and if an IEEE 754 single precision is converted to a decimal string
with at least 9 significant decimal and then converted back to single,
then the final number must match the original).
Sign bit
determines the sign of the number, which is the sign of the
significand as well. Exponent is either an 8 bit signed integer from
−128 to 127 (2's Complement) or an 8 bit unsigned integer from 0 to
255 which is the accepted biased form in IEEE 754 binary32 definition.
For this case an exponent value of 127 represents the actual zero. The
true significand includes 23 fraction bits to the right of the binary
point and an implicit leading bit (to the left of the binary point)
with value 1 unless the exponent is stored with all zeros. Thus only
23 fraction bits of the significand appear in the memory format but
the total precision is 24 bits (equivalent to log10(224) ≈ 7.225
decimal digits).
BTW, I don't get your result. I run this code:
float varr = 123456789;
Console.WriteLine(varr.ToString("#"));
and my output is 123456800
.