Skip to content

Instantly share code, notes, and snippets.

@dustinpoissant
Last active December 1, 2016 03:08
Show Gist options
  • Save dustinpoissant/ace3dd8a3f4edd5ed4e321c7ae51a154 to your computer and use it in GitHub Desktop.
Save dustinpoissant/ace3dd8a3f4edd5ed4e321c7ae51a154 to your computer and use it in GitHub Desktop.
Pasrses a number better than the orginal parseFloat function
function betterParseFloat(num){
num = (num+"").replace(new RegExp(",", 'g'), ""); // Remove commas
return (num.length==0)?0:(isNaN(parseFloat(num)))?betterParseFloat(num.substr(1)):parseFloat(num);
};
function betterParseFloat(a){return a=(a+"").replace(new RegExp(",","g"),""),0==a.length?0:isNaN(parseFloat(a))?betterParseFloat(a.substr(1)):parseFloat(a)}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment