Skip to content

Instantly share code, notes, and snippets.

@IgorHalfeld
Created March 11, 2021 01:31
Show Gist options
  • Save IgorHalfeld/13325a8162bb05d9ccf9a1aa00844797 to your computer and use it in GitHub Desktop.
Save IgorHalfeld/13325a8162bb05d9ccf9a1aa00844797 to your computer and use it in GitHub Desktop.
export const abbreviationNumber = number => {
const qtdMulti = number / 1000;
if (qtdMulti >= 1 && qtdMulti < Math.pow(10, 3)) {
return number / Math.pow(10, 3) + 'K';
}
if (qtdMulti >= Math.pow(10, 3) && qtdMulti < Math.pow(10, 6)) {
return number / Math.pow(10, 6) + 'M';
}
if (qtdMulti >= Math.pow(10, 6) && qtdMulti < Math.pow(10, 9)) {
return number / Math.pow(10, 9) + 'G';
}
return number;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment