Sha256: 077dcc2e392f7404461175a2774c9d3c7014bf53d601213d4f12d18721a3e92f

Contents?: true

Size: 1 KB

Versions: 69

Compression:

Stored size: 1 KB

Contents

define(['./enforcePrecision'], function (enforcePrecision) {

    var _defaultDict = {
        thousand : 'K',
        million : 'M',
        billion : 'B'
    };

    /**
     * Abbreviate number if bigger than 1000. (eg: 2.5K, 17.5M, 3.4B, ...)
     */
    function abbreviateNumber(val, nDecimals, dict){
        nDecimals = nDecimals != null? nDecimals : 1;
        dict = dict || _defaultDict;
        val = enforcePrecision(val, nDecimals);

        var str, mod;

        if (val < 1000000) {
            mod = enforcePrecision(val / 1000, nDecimals);
            // might overflow to next scale during rounding
            str = mod < 1000? mod + dict.thousand : 1 + dict.million;
        } else if (val < 1000000000) {
            mod = enforcePrecision(val / 1000000, nDecimals);
            str = mod < 1000? mod + dict.million : 1 + dict.billion;
        } else {
            str = enforcePrecision(val / 1000000000, nDecimals) + dict.billion;
        }

        return str;
    }

    return abbreviateNumber;

});

Version data entries

69 entries across 69 versions & 2 rubygems

Version Path
trusty-festivity-extension-2.6.3 node_modules/bower/node_modules/mout/src/number/abbreviate.js
trusty-festivity-extension-2.6.2 node_modules/bower/node_modules/mout/src/number/abbreviate.js
trusty-festivity-extension-2.6.1 node_modules/bower/node_modules/mout/src/number/abbreviate.js
trusty-festivity-extension-2.6 node_modules/bower/node_modules/mout/src/number/abbreviate.js
trusty-festivity-extension-2.5.19 node_modules/bower/node_modules/mout/src/number/abbreviate.js
trusty-festivity-extension-2.5.18 node_modules/bower/node_modules/mout/src/number/abbreviate.js
trusty-festivity-extension-2.5.17 node_modules/bower/node_modules/mout/src/number/abbreviate.js
trusty-festivity-extension-2.5.16 node_modules/bower/node_modules/mout/src/number/abbreviate.js
trusty-festivity-extension-2.5.15 node_modules/bower/node_modules/mout/src/number/abbreviate.js
trusty-festivity-extension-2.5.14 node_modules/bower/node_modules/mout/src/number/abbreviate.js
trusty-festivity-extension-2.5.13 node_modules/bower/node_modules/mout/src/number/abbreviate.js
trusty-festivity-extension-2.5.12 node_modules/bower/node_modules/mout/src/number/abbreviate.js
trusty-festivity-extension-2.5.11 node_modules/bower/node_modules/mout/src/number/abbreviate.js
trusty-festivity-extension-2.5.10 node_modules/bower/node_modules/mout/src/number/abbreviate.js
trusty-festivity-extension-2.5.9 node_modules/bower/node_modules/mout/src/number/abbreviate.js
trusty-festivity-extension-2.5.8 node_modules/bower/node_modules/mout/src/number/abbreviate.js
trusty-festivity-extension-2.5.7 node_modules/bower/node_modules/mout/src/number/abbreviate.js
trusty-festivity-extension-2.5.6 node_modules/bower/node_modules/mout/src/number/abbreviate.js
trusty-festivity-extension-2.5.5 node_modules/bower/node_modules/mout/src/number/abbreviate.js
trusty-festivity-extension-2.5.4 node_modules/bower/node_modules/mout/src/number/abbreviate.js