One of the introduced features in .NET 2.0 platform was TryParse() method, very practical and performance wise extension. TryParse method returns a boolean to denote whether the conversion has been successful or not, and returns the converted value through an out parameter. In this test case I will try to present possible bug in converting string value to float by using this method.
float f; string stringValue = "123,456789101112";float.TryParse(stringValue, out f);
String value that needs to be converted to float is 123,456789101112, expected float value after parsing would be the same number, but number 123.456787 was returned. Sixth decimal was wrongly rounded / generated, and instead of 9 - number 7 is placed.Is this conversion culture specific, is some hidden mechanism for rounding applied?Decimal method for parsing string into decimal value is working correctly.
Be careful! ;)