Convert string with exponential number to floating

463 Views Asked by At

I'm working on a NodeJs script that handles strings with exponential values.

Something like this:

1.070000000000000e+003

Which is the best way to convert (or parse) this string and obtain a floating value?

Thanks for the help.

1

There are 1 best solutions below

0
On

You may convert by using parseFloat or Number

If you prefer to parse, maybe the best way is by a regular expression:

/-?(?:0|[1-9]\d*)(?:\.\d*)?(?:[eE][+\-]?\d+)?/

as suggested here and convert the single capturing group.