Created
August 27, 2012 12:24
-
-
Save gdotdesign/3487990 to your computer and use it in GitHub Desktop.
ConvertCurrency
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
| convertCurrency = (input) -> | |
| value = $(input).val().replace /[^\d\.]/g, '' | |
| float = parseFloat(value) | |
| float = 0 if isNaN(float) | |
| precision = parseInt(input.attr('data-precision')) | |
| if precision is 0 | |
| val = float.toString().replace /\.\d*/, '' | |
| else | |
| val = float.toString().replace new RegExp("(\\.\\d{#{precision}})\\d*"), '$1' | |
| val = parseFloat val | |
| $(input).val val || '' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment