Json.NET decimal precision loss

后端 未结 2 1571
轮回少年
轮回少年 2020-12-21 14:16

I have an issue with deserializing decimal value.

JObject.Parse(\"{\\\"available\\\":8777.831438322572000}\")

If I type this code in VS und

2条回答
  •  执念已碎
    2020-12-21 15:14

    I find out that this problem doesn't relate to methods which take destination type as an argument. In case of untyped version method there is a setting which allows to change how json.net treats string with decimal separator. JsonReader.FloatParseHandling default value is FloatParseHandling.Double In my case the way to get correct results is:

    JObject.Load(new JsonTextReader(new StringReader(value)) { FloatParseHandling = FloatParseHandling.Decimal }, null)
    

    JsonSerializer and JsonSerializerSettings contain the same setting.

提交回复
热议问题