I have a line:
"{0:16970861903381446063,length:1}"
I tried converting it to an object using a method eval, but it also evaluates the string and therefore rounds the numeric value, returning:
{0:16970861903381447000,length:1}
I tried passing the number as a string before calling evalon it, using 16970861903381446063 + ''JSON as the value when creating the string; checking it with the help typeofshows that it has a type string, but it still rounds the number 16970861903381446063 to 16970861903381447000.
Is there a way around this or is it better to do this?
Below is the code that generates json text from an array containing numbers
function simplify(arr){
request = "{";
if (arr.length ==1){
request += 0 + ":" + (arr[0] + '') + "," ;
}
else{
for (var i=0;i<=arr.length-1 ;i++){
request += i + ":" + (arr[i] + '') + ",";
}
}
request += "length" + ":" + arr.length +"}";
return request;
}
source
share