0

As in the title, I have very long ID's in my database, and when I import them to node.js by express, in object data is converted to scientific notation, and rounds after 16 places.

31551979034426737773395171961457358310 --> 3.1551979034426736e+37 59493556845631438533043909910482570895 --> 5.949355684563144e+37

value.toLocaleString('fullwide', {useGrouping:false}) = 31551979034426736000000000000000000000

Is there a way to keep the accuracy other than changing type in MySQL to text and then translating it to proper form? I don't see other way because when express receive data it's already rounded. Those are ID's so they need to be represented in accurate form and I don't really want to change all database just cause of js limitations.

Jan Skuza
  • 1
  • 1
  • 2
    Probably the easiest thing to do is import them as strings. You could try using BigInt values as an alternative (add "n" to the end of the numeric constants). – Pointy May 16 '23 at 14:50
  • 1
    Note that the values are not "converted"; exponent notation is how the default presentation of large numbers is done in JavaScript. They're still ordinary JavaScript numbers (with, as you have noted, limited precision). – Pointy May 16 '23 at 14:52

0 Answers0