Created
November 9, 2012 14:09
-
-
Save jasonrhodes/4045860 to your computer and use it in GitHub Desktop.
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 stringToNumber(value) { | |
/** | |
* Interesting facts about JavaScript: | |
* | |
* 1. NaN != NaN | |
* 2. If you pass a string to parseFloat(), it returns NaN | |
* | |
* These facts can be exploited to convert string numbers into numbers. | |
*/ | |
var floatValue = parseFloat(value); | |
return floatValue != floatValue ? value : floatValue; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment