Last active
October 5, 2015 12:07
-
-
Save botic/979c88dcb47d8ab14e41 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
| exports.formatPercent = function(value, notation) { | |
| switch (notation) { | |
| case "floating": { | |
| let remainder = Math.round((value * 10000) % 100); | |
| return Math.floor(value * 100) + (remainder !== 0 ? ("," + (remainder < 10 ? "0" : "") + remainder) : ""); | |
| } | |
| case "human": { | |
| let remainder = Math.round((value * 100) % 100); | |
| return Math.floor(value) + (remainder !== 0 ? ("," + (remainder < 10 ? "0" : "") + remainder) : ""); | |
| } | |
| case "integer": | |
| default: { | |
| let remainder = (value % 100); | |
| return Math.floor(value / 100) + (remainder !== 0 ? ("," + (remainder < 10 ? "0" : "") + remainder) : ""); | |
| } | |
| } | |
| }; |
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
| exports.formatPercent = function(value, notation) { | |
| switch (notation) { | |
| case "floating": floatingPointNotation: { | |
| let remainder = Math.round((value * 10000) % 100); | |
| return Math.floor(value * 100) + (remainder !== 0 ? ("," + (remainder < 10 ? "0" : "") + remainder) : ""); | |
| } | |
| case "human": humanNotation: { | |
| let remainder = Math.round((value * 100) % 100); | |
| return Math.floor(value) + (remainder !== 0 ? ("," + (remainder < 10 ? "0" : "") + remainder) : ""); | |
| } | |
| case "integer": | |
| default: integerNotation: { | |
| let remainder = (value % 100); | |
| return Math.floor(value / 100) + (remainder !== 0 ? ("," + (remainder < 10 ? "0" : "") + remainder) : ""); | |
| } | |
| } | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment