Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion Src/Newtonsoft.Json.Tests/JsonConvertTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1589,6 +1589,14 @@ public void CustomDoubleRounding()
Assert.AreEqual("{\"Positions\":[57.72,60.44,63.44,66.81,70.45],\"Loads\":[23284.0,23225.0,23062.0,22846.0,22594.0],\"Gain\":12345.679}", json);
}

[Test]
public void DoubleRoundTrip()
{
double x = 0.1 + 0.2;
double y = JsonConvert.DeserializeObject<double>(JsonConvert.SerializeObject(x));
Assert.AreEqual(x, y);
}

public class Measurements
{
[JsonProperty(ItemConverterType = typeof(RoundingJsonConverter))]
Expand Down Expand Up @@ -1830,4 +1838,4 @@ private int _expiration
public DateTime Expiration { get; set; }
}
}
}
}
2 changes: 1 addition & 1 deletion Src/Newtonsoft.Json/JsonConvert.cs
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ private static string EnsureFloatFormat(double value, string text, FloatFormatHa
/// <returns>A JSON string representation of the <see cref="Double"/>.</returns>
public static string ToString(double value)
{
return EnsureDecimalPlace(value, value.ToString("R", CultureInfo.InvariantCulture));
return EnsureDecimalPlace(value, value.ToString("G17", CultureInfo.InvariantCulture));
}

internal static string ToString(double value, FloatFormatHandling floatFormatHandling, char quoteChar, bool nullable)
Expand Down