Skip to content

Instantly share code, notes, and snippets.

@Elbone
Created January 29, 2015 03:49
Show Gist options
  • Save Elbone/6e4e4a23b3dd1eabd025 to your computer and use it in GitHub Desktop.
Save Elbone/6e4e4a23b3dd1eabd025 to your computer and use it in GitHub Desktop.
Input to decimal number
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