
function shortNumber(val) {
const abs = Math.abs(val);
const sign = val < 0 ? '-' : '';
const iSymbol = Math.log10(abs) / 3 | 0;
const symbol = 'KMGTPEZY'.charAt(iSymbol - 1);
const short = Math.round(abs / (10 ** (iSymbol * 3)));
return sign + short + symbol;
}shortNumber(96) // '96'
shortNumber(22222) // '22K'
shortNumber(-4951476) // '-5M'