Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Floating-point Formatting and Parsing behavior changed for .NET Core 3.0 #14350
.NET Core 3.0
Formatting and Parsing were updated to be IEEE compliant. This ensures the framework is compliant with the Runtime/Framework specs that dictate we are IEEE 754 compliant and also ensures we match the behavior performed by IEEE compliant languages (such as C#) when they deal with the same string as a "literal" (e.g.
Reason for change
Previously users would not get a string that roundtrips by default. For example, take the following code:
float f = value; string s = f.ToString(); float r = float.Parse(s); bool roundtrips = (f == r);
For some inputs,
Users should read https://devblogs.microsoft.com/dotnet/floating-point-parsing-and-formatting-improvements-in-net-core-3-0/ and review it for the suggested changes. Generally this involves using a different format string (either standard or custom) to enforce getting the desired behavior. Some of the results may not have a workaround as they were previously just incorrect.
This impacts multiple categories from the below as it impacts core methods on a primitive type.
[Choose a category from one of the following: