Javascript not parsing large number in JSON correctly
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-30-2017 10:03 AM
Hi Team,
I have a strange issues foreseeing while trying to use JSON.parse to parse a large number..
When I parse this little piece of JSON
{ "value" : 9223372036854775807 }
that's what I get
{ hello: 9223372036854776000 }
9223372036854775807 != 9223372036854776000
Since javascript can't handle 64bit numbers, when executing JSON.parse
on the response it rounds the number to the maximum value javascript can handle.
Could you please guide me if there is a existing library from ServiceNow to get the right values..
Below is my example where I would like to extract the values for Sydney from the Array,but while doing through in JSON.parse, its returning 602356450160804600 instead of 602356450160804666
[{"id":543709,"name":"POC_Eschborn"},{"id":623141,"name":"Singapore"},{"id":623075,"name":"Pilot_LithiaSprings"},{"id":602356450160804666,"name":"Sydney"},{"id":634196,"name":"New York"},{"id":636478,"name":"Nieuwegein "}]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-30-2017 03:36 PM
you have reached the max for int32.
biginteger - Javascript summing large integers - Stack Overflow
If it was client side you maybe able to include the .js file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-10-2023 06:40 AM
How would I include that .js file?