数字以科学计数法显示 [英] Number displays in scientific notation
问题描述
我的数据返回了json响应,但是当我尝试使用值(数字)之一时,响应将转换为科学计数法.我从来没有遇到过这样的事情,所以我将要发布正在发生的事情.
I am getting a json response back with my data but when I am trying to use one of the values (number) the response is converting to scientific notation. I never encountered something like this so I am just going to post what is happening.
当我使用console.log(response)
时,该值看起来像doctorid":2015031216033174968087
,而当我尝试使用Doctorid时,该值变为2.015031216033175e+21
.即使使用console.log(response.doctorid)
在控制台中输出值,也会发生这种情况.您知道什么可能导致这种行为吗?
When I use console.log(response)
the value looks like that doctorid":2015031216033174968087
and when I am trying to use the doctorid the value becomes 2.015031216033175e+21
. This happens even if I output the value in the console by using console.log(response.doctorid)
. Any idea what might be causing such a behavior?
推荐答案
与python和ruby不同,Javascript不支持任意精度的整数.可以在JS中准确表示的最大数值为 9007199254740991
.较大的数字具有近似的表示形式,并使用科学计数法转换为字符串.
Unlike python and ruby, Javascript doesn't support arbitrary precision integers. The maximal numeric value that can be exactly represented in JS is 9007199254740991
. Bigger numbers have an approximate representation and are converted to strings using scientific notation.
避免这种情况的唯一方法是将ID编码为JSON中的字符串:
The only way to avoid that in your case is to encode IDs as strings in JSON:
"doctorid": "2015031216033174968087"
这篇关于数字以科学计数法显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!