JSFiddle - React, Tailwind, and code Playground

by woozyking

JavaScript

function fwn(n, w, a) {
    var s = '';
    
    if (n >= 1000000) {
        n = n / 1000000;
        s = 'm';
    } else if (n >= 1000) {
        n = n / 1000;
        s = 'k';
    }
    
    return n.toPrecision(w || 5) + s;
}

console.log(fwn(9100000));