Created
January 29, 2015 03:49
-
-
Save Elbone/6e4e4a23b3dd1eabd025 to your computer and use it in GitHub Desktop.
Input to decimal number
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
| inputToDecimalNumber: (Num, Dec) -> | |
| return false if (typeof Num is 'function') | |
| return false if (typeof Num is 'object') | |
| return false if (typeof Num is 'boolean') | |
| return false if (typeof Num is 'undefined') | |
| Num = ''+ Num # Force into string | |
| Num = Num.replace(/[^0-9\.]+/g, '') # Clean up | |
| Num = parseFloat(Num) # Force back into number | |
| Num = Math.round(Num*Math.pow(10,Dec))/Math.pow(10,Dec) | |
| Num = (Num).toFixed(Dec) | |
| return Num |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment