adamwdraper / Numeral-js

A javascript library for formatting and manipulating numbers.
http://numeraljs.com
MIT License
9.64k stars 926 forks source link

Is it possible to have abbreviations, but only up to M? #507

Open andycansdale opened 7 years ago

andycansdale commented 7 years ago

Is their any way to use the standard formatting such as format('0.0 a') and have the number displayed with abbreviations using k and m, but have one billion shown as 1,000m rather than 1.0b?

Silviu-Marian commented 7 years ago

Hey

Looks like there's no option built in for that, for but you can force 'am' instead of 'a' if the number exceeds a billion

var n = 1100000000;
numeral(n).format(`0a${n > 1000000000 && 'm' || ''}`)
// 1100m