diff --git a/Src/Newtonsoft.Json.Tests/JsonConvertTest.cs b/Src/Newtonsoft.Json.Tests/JsonConvertTest.cs index 2582f43a3..f5ac38ef9 100644 --- a/Src/Newtonsoft.Json.Tests/JsonConvertTest.cs +++ b/Src/Newtonsoft.Json.Tests/JsonConvertTest.cs @@ -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(JsonConvert.SerializeObject(x)); + Assert.AreEqual(x, y); + } + public class Measurements { [JsonProperty(ItemConverterType = typeof(RoundingJsonConverter))] @@ -1830,4 +1838,4 @@ private int _expiration public DateTime Expiration { get; set; } } } -} \ No newline at end of file +} diff --git a/Src/Newtonsoft.Json/JsonConvert.cs b/Src/Newtonsoft.Json/JsonConvert.cs index 95019e2b7..a047d679a 100644 --- a/Src/Newtonsoft.Json/JsonConvert.cs +++ b/Src/Newtonsoft.Json/JsonConvert.cs @@ -292,7 +292,7 @@ private static string EnsureFloatFormat(double value, string text, FloatFormatHa /// A JSON string representation of the . 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)