Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Abbreviate large numbers in Javascript (as a es6 module)
export default function abbreviateNumber(value) {
let newValue = value;
const suffixes = ["", "K", "M", "B","T"];
let suffixNum = 0;
while (newValue >= 1000) {
newValue /= 1000;
newValue = newValue.toPrecision(3);
newValue += suffixes[suffixNum];
return newValue;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment