Created
March 8, 2018 02:38
-
-
Save keulraesik/9a83dfad4f98bb03a2767544e98f6d18 to your computer and use it in GitHub Desktop.
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
| var keepDecimalPlacesBy = function (v, dp=2) { | |
| if (isNaN(v * 1)) return v; | |
| v = v.toString(); | |
| var parts = v.split('.'); | |
| console.log(parts); | |
| if (parts) { | |
| switch (parts.length) { | |
| case 1: | |
| return v; | |
| case 2: | |
| let p2 = parts[1].length > dp ? parts[1].substr(0, 2) : parts[1]; | |
| return parts[0] + '.' + p2; | |
| default: | |
| return v; | |
| } | |
| } | |
| return v; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment