/ Published in: JavaScript

it parses given string and returns 1st number it encounters ( it will replace comas with dots so floats formatted as 12,345 could be 12.345 ( some countries use that ) )
then u can parse returned value as a number / float / int - do what You need with it ;-)
then u can parse returned value as a number / float / int - do what You need with it ;-)
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
(/[\d.]+/).exec((__PROVIDE_STRING_TO_PARSE__).replace(",", ".")) // if u want it to make even more dumb-proof ( like multiple dots/comas "within" the number ) use this: (/[\d]+.?[\d]+/).exec((__PROVIDE_STRING_TO_PARSE__).replace(",", "."))
Comments
