neuecc / Utf8Json

Definitely Fastest and Zero Allocation JSON Serializer for C#(NET, .NET Core, Unity, Xamarin).
MIT License
2.35k stars 266 forks source link

Unable to Deserialize some doubles e.g. "59.08634249999999" will be "5.90863425E+15" #243

Open tomsoftware opened 3 years ago

tomsoftware commented 3 years ago

Some Float-Point Numbers are not Deserialize correctly

Example:

var x = JsonSerializer.Deserialize<object>("{\"a\":59.08634249999999}");

will result in

{[a, 5.90863425E+15]}
tomsoftware commented 3 years ago

@neuecc : It seems like you do not maintain this library anymore... that's a pity. Can you maybe note that on the readme page or name a new maintainer?

For example this Issue feels really bad cause it occurs only sporadically on some numbers (the example-number and it's number of digits was first triggert by simply using JSON.Stringify() ) and if no one is able to fix issues like this no one should use this library :-(

alex-vorobyev commented 2 years ago

Your example are deserialize correctly if use decimal type:

public class ClassA { public decimal A { get; set; } }

var x = JsonSerializer.Deserialize<ClassA>("{ \"A\": 59.08634249999999 }");