Created
February 25, 2016 20:54
-
-
Save JDMcKinstry/d4fccec14223eb021c3e to your computer and use it in GitHub Desktop.
Convert string to Int || Float
This file contains hidden or 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
| if (Object['defineProperty'] && !String.prototype.hasOwnProperty('toInt')) Object.defineProperty(String.prototype, 'toInt', { value: function() { return parseFloat(this.replace(/[^0-9|.]/g, '').replace(/^0+/g, '')); } }); | |
| // Get any string into an INT or FLOAT, if it has a period | |
| "jafs98y934hrqrjn34.wf.4e3whtw0g78sbenh bsghers.".toInt() // 9893434 | |
| "a1b2@&%92.234dfg.64%^564j.thyj5.67!~56.3453 v3".toInt() // 1292.234 | |
| "55.66.77".toInt(); // 55.66 | |
| "$4.55".toInt(); // 4.55 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment