Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Floating-point Formatting and Parsing behavior changed for .NET Core 3.0 #14350

tannergooding opened this issue Sep 10, 2019 · 0 comments


Copy link

commented Sep 10, 2019

[Change Title]

Floating-point (System.Double and System.Single) formatting and parsing were changed to be IEEE compliant for .NET Core 3.0

Version introduced

.NET Core 3.0

Old behavior

Formatting (ToString) and Parsing (Parse and TryParse) were previously not IEEE compliant and it was impossible to guarantee that a value would roundtrip under any supported standard or custom numeric format string.

New behavior

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. float f = 1.0f where 1.0f is a literal).

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, float.Parse(s) could fail. For other inputs, roundtrips would be false.

Recommended action

Users should read 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:

  • ASP.NET Core
  • C#
  • Core
  • CoreFx
  • Data
  • Debugger
  • Deployment for .NET Core
  • Globalization
  • interop
  • JIT
  • LINQ
  • Managed Extensibility Framework (MEF)
  • MSBuild
  • Networking
  • Printing
  • Security
  • Serialization
  • Visual Basic
  • Windows Forms
  • Windows Presentation Foundation (WPF)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
2 participants
You can’t perform that action at this time.