Reputation: 8655
In my app, I want to format various numbers using a library, and I have a couple of related questions (which I don't submit separately because I think they might represent a very common set of problems)
1.2k
or 1.23M
I tried to achieve a formatting result, where the language thousand delimiter is actually taken into consideration
http://jsfiddle.net/erbronni/19mLmekt/
// load a language
numeral.language('fr', {
delimiters: {
thousands: ' ',
decimal: ','
},
abbreviations: {
thousand: 'k',
million: 'M',
billion: '',
trillion: 't'
},
ordinal : function (number) {
return number === 1 ? 'er' : 'ème';
},
currency: {
symbol: '€'
}
});
numeral.language('fr');
document.getElementById('f1').innerHTML = numeral(12345678).format('0 000') // intended output: '12 345 678' -- does not seem to work
Upvotes: 3
Views: 6407
Reputation: 1950
Numeral.js has this built in. It can be easily achieved using a
such as .format('0.00a')
.
Some full examples:
numeral(1000000).format('0a')
will return 1m
numeral(250500).format('0.0a')
will return 250.5k
numeral(10500).format('0.00a')
will return 10.50k
Upvotes: 6