Bug when serializing a float

Jul 17, 2012 at 9:49 AM

if you run this code

Dim i As Single? = 5.2
Dim o1 As New JObject(New JProperty("i", i))

Dim s As String = o1.ToString(Newtonsoft.Json.Formatting.None)

 

the rendered JSON has i with a value of 5.199999998. this is because of the Convert.ToDouble call when writing the property (.NET might change the value when converting from single to double) .

 

to fix this the code should check if the value is of type single and if so call the appropriate write overload

 

Coordinator
Jul 18, 2012 at 6:29 AM

Will fix