1

If I type a number in the browser console the result is:

1000000000000000000000 --> 1e+21
0.00000000003453 --> 3.453e-11

I want to determine the number after e. In this example, the number is 21 or -11

Thanks!

Nick Parsons
  • 45,728
  • 6
  • 46
  • 64
Matt Nguyen
  • 45
  • 1
  • 5

1 Answers1

2

You can convert the number to a string using .toExponential() and then split based on e and get the last element (which would be your number) like so:

const getExp = n =>
  +(n.toExponential().split('e').pop())

console.log(getExp(1000000000000000000000)) // 21
console.log(getExp(0.00000000003453)); // -11
console.log(getExp(0.000324)); // -4
Nick Parsons
  • 45,728
  • 6
  • 46
  • 64