-1

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.

Federico
  • 1,003
  • 4
  • 15
  • 31

1 Answers1

0

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.

Matteo Ragni
  • 2,689
  • 1
  • 21
  • 31