Skip to content

Instantly share code, notes, and snippets.

@sorz
Created February 18, 2014 14:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sorz/9072296 to your computer and use it in GitHub Desktop.
Save sorz/9072296 to your computer and use it in GitHub Desktop.
function matchFloat(s) {
f = s.replace(/[^\d]+/g, '');
g = s.split(/\d/);
if (g.length == 0)
return f;
else if (g[0].contains('-'))
f = '-' + f;
for (var i=0; i<g.length - 1; i++)
if (g[i].contains('.'))
return f / (10 * Math.pow(10, g.length - i - 2));
return f;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment