Skip to content

Instantly share code, notes, and snippets.

@botic
Last active October 5, 2015 12:07
Show Gist options
  • Select an option

  • Save botic/979c88dcb47d8ab14e41 to your computer and use it in GitHub Desktop.

Select an option

Save botic/979c88dcb47d8ab14e41 to your computer and use it in GitHub Desktop.
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) : "");
}
}
};
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