I am using ASP.NET core web application that fetches some data from database and returns a data transfer object serialized to JSON. I have noticed that when the data contains a big number (e.g. 70679185527693127) then the number is rounded when pretty-printed. I inspected the returned JSON using browser developer tools (Firefox & Chrome) and raw data is correct, but incorrect when pretty-printed. I have also tried to pretty-print the JSON using this website and the results are still the same. This is for some reason a problem for my Kendo grid that I am trying to show the data in as it shows the wrong rounded data. Why is that? Do I have to avoid using such big numbers?
Here is the very simplified JSON:
{"Data":[{"Id":70679185527693127}],"Total":1}
Here is the pretty-printed version:
{
"Data": [
{
"Id": 70679185527693130
}
],
"Total": 1
}
See the difference in the values.
EDIT: Passing the value as a string works as expected (atleast using the mentioned website). Also a side question: why does the Kendo grid show the pretty-printed data instead of parsing the raw data which seem to be correct?
Pretty print is realized via JSON.parse() + JSON.stringify().
The value of your Id exceeds Number.MAX_SAFE_INTEGER so JSON.parse() will possibly parse an incorrect value.
I assume Kendo also uses JSON.parse() and thus will also display wrong values.
See also this question for more information
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With