-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Deserialize decimal same code results not match #2928
Comments
There is no error in the output of the web application. Rather, the Intellisense output of the WPF app does not align with Newtonsoft.Json's default deserialization settings. By default (unless configured otherwise), Newtonsoft.Json uses the This however poses the question of why you did not see 422.3219999999997 in the Intellisense inspector for your WPF app. I can only speculate here:
I suggest you do a more fine-grained inspection of what Newtonsoft.Json did actually deserialize in your WPF app (and that bypasses possible Intellisense inspector presentation issues like the one i speculated about): var jvalue = (JValue)((JObject)obj)["Data"];
var tokenType = jvalue.Type;
var valueType = jvalue.Value.GetType().FullName;
var fullPrecisionValue = $"{jvalue.Value:G17}"; If the Newtonsoft.Json default settings are used (i.e. no custom JsonSerializerSettings), the variables should contain the following: tokenType: JTokenType.Float If the token type or the value type indicate a System.Decimal value being deserialized instead of a System.Double, then this is indicative of your WPF app having set up custom JsonSerializerSettings through |
@elgonzo , Thank you for your reply。 Currently, the issue is being fixed on the web by setting FloatParseHandling=FloatParseHandling.Decimal; Thanks. |
NF 4.8 , console output:422.3262, .net core 8 console output: 422.3219999999997, NF4.8 web application output: 422.3219999999997
It looks like it's due to different framework double.TryParse results are inconsistent; |
Source/destination types
Source/destination JSON
Expected behavior
output: {"Data":422.3262}
Actual behavior
output: {"Data":422.3219999999997}
Steps to reproduce
Newtonsoft.Json:13.0.2
NF4.8
Same code,
var str = JsonConvert.SerializeObject(new { Data = 422.3262M });
var obj = JsonConvert.DeserializeObject(str);
Web application obj output: 422.3219999999997
wpf or console obj output:422.3262
but web application set FloatParseHandling =FloatParseHandling.Decimal,output :422.3262,
Why do the same code results not match?
web app output error:
wfp output:
web application ok:
The text was updated successfully, but these errors were encountered: