Skip to content

Commit 9a51033

Browse files
committed
try: fix floating-point formatting on Windows
1 parent a9769f8 commit 9a51033

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

test/Sentry.Tests/SentryLogTests.cs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -221,20 +221,22 @@ public static string Format(this DateTimeOffset value)
221221

222222
public static string Format(this double value)
223223
{
224-
// since .NET Core 3.0, the Floating-Point Formatter returns the shortest roundtrippable string, rather than the exact string
225-
// e.g. on .NET Framework (Windows)
226-
// * 2.2.ToString() -> 2.2000000000000002
227-
// * 4.4.ToString() -> 4.4000000000000004
228-
// see https://devblogs.microsoft.com/dotnet/floating-point-parsing-and-formatting-improvements-in-net-core-3-0/
229-
230-
if (!IsWindows)
224+
#if NETFRAMEWORK
225+
if (IsWindows)
231226
{
232-
return value.ToString(NumberFormatInfo.InvariantInfo);
227+
// since .NET Core 3.0, the Floating-Point Formatter returns the shortest roundtrippable string, rather than the exact string
228+
// e.g. on .NET Framework (Windows)
229+
// * 2.2.ToString() -> 2.2000000000000002
230+
// * 4.4.ToString() -> 4.4000000000000004
231+
// see https://devblogs.microsoft.com/dotnet/floating-point-parsing-and-formatting-improvements-in-net-core-3-0/
232+
233+
var utf16Text = value.ToString("G17", NumberFormatInfo.InvariantInfo);
234+
var utf8Bytes = Encoding.UTF8.GetBytes(utf16Text);
235+
return Encoding.UTF8.GetString(utf8Bytes);
233236
}
237+
#endif
234238

235-
var utf16Text = value.ToString("G17", NumberFormatInfo.InvariantInfo);
236-
var utf8Bytes = Encoding.UTF8.GetBytes(utf16Text);
237-
return Encoding.UTF8.GetString(utf8Bytes);
239+
return value.ToString(NumberFormatInfo.InvariantInfo);
238240
}
239241
}
240242

0 commit comments

Comments
 (0)