Javascript and the big integer imprecision… or the WTF with my mysql ids ?

Ever tried to send mysql id over json ? just some small things to know before you try…

open a javascript console and type the following:

first try a stupid echo :

 23278053098520648
 > 23278053098520650

hum ok echo is not working correctly

Let’s try with a number object:

 i=Number(23278053098520648);
 > 23278053098520650

again… ok it is a too big number, let see what is the max:

 i=Number.MAX_VALUE
 > 1.7976931348623157e+308

wow javascript can handle really big number… but with an imprecision of 16 digits and of course mysql ids are 17 digits… so you have to handle mysql ids as string.