Deserializing decimal -> removes trailing zero
See original GitHub issueAfter migrating to Json.Net 10 the behaviour of deserializing decimals has changed. In Json.Net 9 the trailing zeros also exists after deserialization. Not so in version 10. The JSON string after serialization looks identical in versions 9 and 10.
Expected behavior
I would expect that trailing zeros exists after deserialzation, e. g. 87.50
Actual behavior
After deserialization the trailing zeros doesn’t exists.
Steps to reproduce
var money1 = 87.50m;
Console.WriteLine($"Before Json-Serialization: {money1}");
var jsonString = JsonConvert.SerializeObject(money1);
Console.WriteLine($"Json-String: {jsonString}");
var money2 = JsonConvert.DeserializeObject<decimal>(jsonString);
Console.WriteLine($"After Json-Serialization: {money2}");
The console output lookes as follows:
Before Json-Serialization: 87.50 Json-String: 87.50 After Json-Serialization: 87.5
With Json.Net 9 the output looks as follows:
Before Json-Serialization: 87.50 Json-String: 87.50 After Json-Serialization: 87.50
Issue Analytics
- State:
- Created 6 years ago
- Comments:12 (5 by maintainers)
Top Results From Across the Web
Preserving trailing zeros when selecting values from Json ...
Because C# decimal types preserve trailing zeros, you can just instruct Json.Net to parse numbers to decimals instead of floating points.
Read more >JsonObject drops trailing zero from decimal type in REST ...
This type trims trailing zeros by default. It's up to the client/receiver of the JSON to decide how many decimal places it needs...
Read more >How to remove trailing zeros in a decimal - C#
The following program explains how to remove the trailing zeros in a decimal type. Also, it is doing the rounding operation also. Example:...
Read more >Preserving trailing zeros when selecting values from Json ...
Because C# decimal types preserve trailing zeros, you can just instruct Json.Net to parse numbers to decimals instead of floating points.
Read more >How to configure the serialization of floats?
ArduinoJson uses as few digits as possible: it doesn't add trailing zeros. It uses up to 9 decimal places; this is a limitation...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I just created the PR #1368 to fix this.
I am having have this issue with when deserialize string to xmlDocument
XmlDocument doc = JsonConvert.DeserializeXmlNode(stringval, "Root");