Wonderful World of ToString
Interesting experience reading a text file and converting strings to numbers. It seems the standard string converter is subject to rounding. You can see the details on msdn.
It’s not immediately obvious from the docs, but here’s what I found in the Immediate window:
I had numbers that represented dates:
(Single) 20091022 20091022.0
The standard ToString was in exponential format, that was the first unexpected result:
((Single) 20091022).ToString() "2.009102E+07"
When using a formatting specifier, the last digit was cut off:
((Single) 20091022).ToString("#") "20091020"
How and why this relates to the culture setting as per the docs is beyond me. My personal culture says that numbers before the decimal point are significant. It has the same precision as the exponential format.
To fix the problem, I chose the “r” specifier. R is for round trip, what you get can be converted back to what you had:
((Single) 20091022).ToString("r") "20091022"