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

Round-trip format specifier incorrect for some doubles on some x64 computers #3313

hickford opened this issue Feb 23, 2016 · 2 comments


Copy link

commented Feb 23, 2016

Reproduced from

Recently I have had to serialize a double into text, and then get it back. The value seems to not be equivalent:

double d1 = 0.84551240822557006;
string s = d1.ToString("R");
double d2 = double.Parse(s);
bool s1 = d1 == d2;
// -> s1 is False

But according to MSDN: Standard Numeric Format Strings, the "R" option is supposed to guarantee round-trip safety.

The round-trip ("R") format specifier is used to ensure that a numeric value that is converted to a string will be parsed back into the same numeric value

Why did this happen?

@sergiy-k sergiy-k modified the milestone: Future Jun 8, 2016


This comment has been minimized.

Copy link

commented Feb 27, 2017

According to there are programs that rely on this behavior and the documentation has been updated with a workaround that you should implement R yourself for x64. Unfortunately that workaround does not work in practice since there are many places like XmlConvert where it is not possible to override how doubles are formatted.


This comment has been minimized.

Copy link

commented Feb 1, 2019

Now that #22040 is merged, for .NET Core 3.0, ToString(), ToString("G"), ToString("R"), double.ToString("G17"), and float.ToString("G9") should now always produce a string that will roundtrip to the original value..

I will keep this open until an explicit testcase for 0.84551240822557006 can be added to CoreFX.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
4 participants
You can’t perform that action at this time.