6

I have a WCF service operation that returns an object with long and List<string> properties. When I test the operation in a WCF application, everything works fine and the values are correct. However, I need to be able to call the service using jQuery and JSON format. The value of the long property apparently changes when I read it back in the OnSucceed function.

After searching I've found that JSON.stringify changes big values. So in code like this:

alert(JSON.stringify(25001509088465005));

...it will show the value as 25001509088465004.

What is happening?

Demo here: http://jsfiddle.net/naveen/tPKw7/

1 Answers1

4

JavaScript represents numbers using IEEE-754 double-precision (64 bit) format. As I understand it this gives you 53 bits precision, or fifteen to sixteen decimal digits. Your number has more digits than JavaScript can cope with, so you end up with an approximation.

Do you need to do maths operations on this big number? Because if its just some kind of ID you can return it as a string and avoid the problem.

nnnnnn
  • 147,572
  • 30
  • 200
  • 241