Шукати в статтях підтримки

Остерігайтеся нападів зловмисників. Mozilla ніколи не просить вас зателефонувати, надіслати номер телефону у повідомленні або поділитися з кимось особистими даними. Будь ласка, повідомте про підозрілі дії за допомогою меню “Повідомити про зловживання”

Learn More

Ця тема перенесена в архів. Якщо вам потрібна допомога, запитайте.

json for long

  • 1 відповідь
  • 2 мають цю проблему
  • 4 перегляди
  • Остання відповідь від Banban

more options

when i return from server long 134413929815213133

in console.log - i have 134413929815213140

if i return long as string in console right value 134413929815213140

when i return from server long 134413929815213133 in console.log - i have 134413929815213140 if i return long as string in console right value 134413929815213140
Прикріплені знімки екрана

Змінено KANekT

Обране рішення

Numbers in Javascript have 64 bits :

  • 1 bit for the sign (+ or -)
  • 11 bits to store the location of the point in the number
  • 52 bits for the number itself

2^52 = 4 503 599 627 370 496 (~ 4.5x10^15), so if you assign numbers greater than 2^52, results are uncertain up to ~ 10^308 (it's infinite over).

If you don't need to do operations on these big numbers, using strings is indeed a good solution.

See this MDN article about Number type and ECMAScript standard page for more information.

Читати цю відповідь у контексті 👍 1

Усі відповіді (1)

more options

Вибране рішення

Numbers in Javascript have 64 bits :

  • 1 bit for the sign (+ or -)
  • 11 bits to store the location of the point in the number
  • 52 bits for the number itself

2^52 = 4 503 599 627 370 496 (~ 4.5x10^15), so if you assign numbers greater than 2^52, results are uncertain up to ~ 10^308 (it's infinite over).

If you don't need to do operations on these big numbers, using strings is indeed a good solution.

See this MDN article about Number type and ECMAScript standard page for more information.