Marielle Lapidario Marielle Lapidario - 2 months ago 8
Javascript Question

How to convert string (number with prefix) to Double/Float in JS

How to convert a number with prefix into

double/float
e.g.
STA01.02
to
1.02
?

J S J S
Answer

Use regex to strip the non-numbers (excluding ".") for a more flexible solution:

parseFloat("STA01.02".replace(/[^0-9\.]+/g, ''));