Numeral-js: question: what would be the simplest way to customize abbreviations?

Created on 10 Mar 2014  Â·  6Comments  Â·  Source: adamwdraper/Numeral-js

for instance, my designer wants a capital 'M' for millions v lowercase 'm',
i see i could overwrite my entire locale spec, but i was hoping for a more terse way,
something like:

numeral.language().override({abbreviations: {million: 'M'}})

or i could use underscore/lodash extend() or default() against the abbreviation object if there was a method to return it, but right now it looks like numeral.language() just returns the string name of the language...

regards,
tony.

Most helpful comment

In chinese culture, we don't use thousands as a delimiter, but in 10k, as a '1万'.
Is there any way to make a custom 4 digit per delimiter local config?

All 6 comments

You can do

e.language("en", {
            delimiters: {
                thousands: ",",
                decimal: "."
            },
            abbreviations: {
                thousand: "K",
                million: "M",
                billion: "B",
                trillion: "T",
            },
        ordinal: function(e) {
            var t = e % 10;
            return~~ (e % 100 / 10) === 1 ? "th" : t === 1 ? "st" : t === 2 ? "nd" : t === 3 ? "rd" : "th"
        },
        currency: {
            symbol: "$"
        }
    });

I came with the same question -- on the numeral home page, I can run numeral.languageData() and get back the object configuring the language. Then I could make my change and away we go -- but it doesn't seem possible with the version on CDN.

In other words, I think we want to be able to tweak the abbreviation without having to tweak anything else. Seems simple but not possible?

@cymen you should be able to using the CDN version as it shouldn't be any different then having the JS loaded locally.

You can modify the object that's returned from numeral.languageData() using underscore/lodash to change just the abbreviations or do as @wopian showed to overwrite everything.

_.assign(numeral.languageData('en'), {
    abbreviations: {
        thousand: "K",
        million: "M",
        billion: "B",
        trillion: "T"
    }
});

In my case, I didn't want abbreviations enabled so I null them out:

_.assign(numeral.languageData(), { abbreviations: {} })

It is currently numeral.localeData('en').

In chinese culture, we don't use thousands as a delimiter, but in 10k, as a '1万'.
Is there any way to make a custom 4 digit per delimiter local config?

i disabled abbreviations and currencies by adding following two line after setting up locale for numeral

numeral.localeData().abbreviations = {};
numeral.localeData().currency = {};

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jonathanbergson picture jonathanbergson  Â·  6Comments

Eric24 picture Eric24  Â·  8Comments

amirtgm picture amirtgm  Â·  6Comments

meafmira picture meafmira  Â·  8Comments

MisterGoodcat picture MisterGoodcat  Â·  3Comments