Stop Javascript from rounding large numeric identifiers

The following window is issued with a warning: 211466719468855300. Why does this happen even when I try to pass it to a String? How can I read it for sure?

HTML:

<a class="delete-link" data-id="211466719468855298">Delete</a>​

JS:

$('.delete-link').click(function(e) {
        var $item =$(this);
        var itemID = String($item.data('id'));
        alert(itemID);
});

Fiddle: http://jsfiddle.net/zUbym/1/

+5
source share
1 answer

There are two reasons for this:

  • jQuery helps you convert data attribute values ​​to corresponding types.
  • Numbers that cannot be represented exactly in JavaScript because all numbers are 64-bit IEEE 794 floating point values.

".attr()" , , . , ( "_" - ), JQuery .

+8

All Articles