Replace all occurrences of scientific numbers with regular numbers

Viewed 75

I've got a large XML string with decimal values in regular and scientific notation. I need a way to convert all the exponential values to regular notation in-place.

So far I've put together the following Regex which grabs every instance of a exponential number.

/-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/

And I can convert those to regular notation using:

Number('1.255262969126037e-14').toFixed();

Now how do I put it all together; How do I find and replace all occurrences of scientific notation values with regular notation, in-place?


Considering the following input:

<path class="arc" d="M1.3807892660386408e-14,-225.50000000000003A225.50000000000003,225.50000000000003 0 0,1 219.47657188958337,51.77146310079094L199.52415626325757,47.06496645526448A205,205 0 0,0 1.255262969126037e-14,-205Z">

I need the following output:

<path class="arc" d="M0,-225.50000000000003A225.50000000000003,225.50000000000003 0 0,1 219.47657188958337,51.77146310079094L199.52415626325757,47.06496645526448A205,205 0 0,0 0,-205Z">

1 Answers
Related