Last active
December 1, 2016 03:08
-
-
Save dustinpoissant/ace3dd8a3f4edd5ed4e321c7ae51a154 to your computer and use it in GitHub Desktop.
Pasrses a number better than the orginal parseFloat function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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