From b62c0286c40c711746cdaa793df741fd34685a78 Mon Sep 17 00:00:00 2001 From: yadoer Date: Sun, 28 May 2017 11:18:29 +0800 Subject: [PATCH] Update Compare method@JValue.cs (#1310) For JTokenType.Float, we should add the comparison for decimal type. --- Src/Newtonsoft.Json.Tests/Linq/JValueTests.cs | 3 ++- Src/Newtonsoft.Json/Linq/JValue.cs | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Src/Newtonsoft.Json.Tests/Linq/JValueTests.cs b/Src/Newtonsoft.Json.Tests/Linq/JValueTests.cs index 7a731775..ebd44444 100644 --- a/Src/Newtonsoft.Json.Tests/Linq/JValueTests.cs +++ b/Src/Newtonsoft.Json.Tests/Linq/JValueTests.cs @@ -341,6 +341,7 @@ namespace Newtonsoft.Json.Tests.Linq Assert.IsTrue(JToken.DeepEquals(new JValue(5L), new JValue(5))); Assert.IsFalse(JToken.DeepEquals(new JValue(5M), new JValue(5))); Assert.IsTrue(JToken.DeepEquals(new JValue((ulong)long.MaxValue), new JValue(long.MaxValue))); + Assert.IsFalse(JToken.DeepEquals(new JValue(0.102410241024102424m), new JValue(0.102410241024102425m))); } [Test] @@ -852,4 +853,4 @@ namespace Newtonsoft.Json.Tests.Linq } #endif } -} \ No newline at end of file +} diff --git a/Src/Newtonsoft.Json/Linq/JValue.cs b/Src/Newtonsoft.Json/Linq/JValue.cs index 2fbc747f..14fd5749 100644 --- a/Src/Newtonsoft.Json/Linq/JValue.cs +++ b/Src/Newtonsoft.Json/Linq/JValue.cs @@ -297,6 +297,10 @@ namespace Newtonsoft.Json.Linq return -CompareBigInteger((BigInteger)objB, objA); } #endif + if (objA is ulong || objB is ulong || objA is decimal || objB is decimal) + { + return Convert.ToDecimal(objA, CultureInfo.InvariantCulture).CompareTo(Convert.ToDecimal(objB, CultureInfo.InvariantCulture)); + } return CompareFloat(objA, objB); case JTokenType.Comment: case JTokenType.String: