How to convert 2.79470525274901e+28
id to number in Java Script?
Asked
Active
Viewed 764 times
-1

Barmar
- 741,623
- 53
- 500
- 612

Udaya Vani
- 513
- 1
- 6
- 20
1 Answers
0
You can pass it to new Number()
:
const a = new Number('1e+5');
This will make it a number object. It'll work just like a normal number, and then you can do other things with it:
const a = new Number('1e+5') + 5;
console.log(a);
Do note, that if that is an id
, meaning it's a really long number, then you'll probably have issues. If you take something like this:
2.79375892768972378067309875980271598721390687239086729387698
it'll turn into something like this:
2.792573895732e+30 // didn't actually count, just an example
However, when it's converted back, everything after that last 2 gets turned into a zero:
2.79257389573200000000000000000000000000000000000000000000000
This is due to the limits of precision of JavaScript's number.
Thus, if that ID is a number and not just a string that looks like a number, there would be no way to restore it to its original form.

samanime
- 25,408
- 15
- 90
- 139