Update Compare method@JValue.cs (#1310)
For JTokenType.Float, we should add the comparison for decimal type.
This commit is contained in:
committed by
James Newton-King
parent
f523b2d3bc
commit
b62c0286c4
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user