Ruutert
Ruutert

Reputation: 395

jQuery get JSON result with large decimals not working correctly

I'm using jQuery $.ajax to call a webservice. The result is JSON data with a lot of data and large decimals. In Fiddler, a result in JSON is displayed as

-1.34337916794034E+18

When I'm using Textview in Fiddler i'm getting the (right) result

-1343379167940340394.0

My ajax function:

$.ajax({
    type: method,
    beforeSend: function (request) {
        ShowLoader();
        request.setRequestHeader(requestHeaderName, requestHeaderValue);
    },
    accepts: "gzip, deflate",
    url: methodUrl,
    contentType: "application/json; charset=utf-8",
    crossDomain: true,
    data: jsonParams,
    dataType: 'json',
    success: function (responseData) {
        return callback(responseData);
    },
    complete: function () {
        HideLoader();
    }
});

Why is this? Is this a problem in JSON / jQuery ? The webapplication is also using ASP.NET (Forms).

Please help.

Upvotes: 0

Views: 992

Answers (1)

nderscore
nderscore

Reputation: 4251

The problem is that JavaScript's floating point number system cannot work (at least not precisely) with a number that long. You could try using a library like Big.js

Upvotes: 1

Related Questions