Mottie / javascript-number-formatter

Lightweight & Fast JavaScript Number Formatter
http://mottie.github.io/javascript-number-formatter/
MIT License
141 stars 37 forks source link

Support numeralJs-like abbreviations #14

Open jfstephe opened 6 years ago

jfstephe commented 6 years ago

Hi, I noticed recently that NumeralJs includes abbreviations such as:

|    value | format | result
|  1230974 | '0.0a' |   1.2m
|     1460 |  '0 a' |    1 k
|  -104000 |   '0a' |  -104k

I was wondering if you had any plans on supporting such functionality? I mention it only because I know you are looking into rewriting this library and if it's not too much hassle this would be great to support. As an aside, NumeralJs also supports 'order' (1st, 2nd etc) too.

If/when this becomes critical to me I'll happily look into creating a PR.

Many thanks as always! John

Mottie commented 6 years ago

Hi @jfstephe!

I was planning on making this library support an Excel-like format. For example, this would be a mask setting:

// positive number; negative number; zero
mask: "#,###.00_);(#,###.00); 0.00";

I would like to keep this library simple, so I don't have plans to support every aspect of the Excel format. And I don't think I'll add support for abbreviations or ordinals because it looks like NumeralJs is doing a fine job at it already; but who knows, I may change my mind in the future.

jfstephe commented 6 years ago

NumeralJs does do the abbreviations etc well but it's not compatable with my use cases as, IMHO, numeralJs isn't great with regards currency symbols and locales (see this issue).

It would be great to have one number formatter to rule them all, but I understand your viewpoint. I mentioned it now incase it's easy to cater for when doing your re-write. If/when I need it I'll create a PR and you can decide to include it or not. :-)

Thanks, John