Вопрос

I'm trying to convert "9999999999999099" into a number/float in javascript. The problem is that both parseFloat(X) and Number(X) return 9999999999999100.

This is not the same number. Does anyone know why this happens and how to avoid it? Thanks in advance.

Это было полезно?

Решение

Both numbers have the same floating point representation, because floating point numbers are only accurate to a certain level.

If these numbers are for calculation, why do you need to convert them with better than 1 in a quadrillion precision? If these values are not for calculation, leave them as strings.


By not for calculation, I mean something like a phone number or ID card number. It's meaningless to add or multiply phone numbers together.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top