I am migrating an application from the .NET Framework 4.6.2 to .NET Core 3.1 and my unit tests failed in a place I did not expect.
After some calculations, I ended up with a double with 16 digits. According to the debugger, I got the exact same value whether I am running the .NET462 or the .NETCore31 code. The difference occurs when I "serialize" this value. In the .NETCore31 version, the last digit is lost:
Here is an exemple:
.NET
4.0584789241077042.ToString("R", CultureInfo.InvariantCulture)
// "4.0584789241077042" (the exact same number)
.NET Core
4.0584789241077042.ToString("R", CultureInfo.InvariantCulture);
// "4.058478924107704" (the last digit is gone)
It is not actually an issue, my calculation does not require such precision, but does anyone know why I am getting two different results?