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