Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@sturmenta
Created July 22, 2019 22:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sturmenta/82e7560da7af3f94d2a184b56550e5b6 to your computer and use it in GitHub Desktop.
Save sturmenta/82e7560da7af3f94d2a184b56550e5b6 to your computer and use it in GitHub Desktop.
Parse big numbers
const values = [
{ K: 1000 },
{ M: 1000000 },
{ B: 1000000000 },
{ Qd: 1000000000000 },
{ Qt: 1000000000000000 },
{ St: 1000000000000000000 },
{ Sp: 1000000000000000000000 },
{ O: 1000000000000000000000000 },
{ N: 1000000000000000000000000000 },
{ D: 1000000000000000000000000000000 },
];
export const formatBigNumber = vigitScore => {
let vigitScoreParsed;
values.forEach(value => {
const letter = Object.keys(value)[0];
if (vigitScore / value[letter] < 999 && vigitScore / value[letter] > 1)
vigitScoreParsed = `${Math.round((vigitScore / value[letter]) * 100) / 100} ${letter}`;
});
return vigitScoreParsed || Math.round(vigitScore * 100) / 100;
};
// input - 3181.12139983
// output - 3.18 K
// input - 350.12352345
// output - 350.12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment