0

I'm a beginner programmer, I've just been making a game to play on Discord. It's working fine so far, but so far as fine-tuning, I've come into a problem with numeral.js that I can't seem to find any good references so far as how to fix.

In the game, numbers can get extremely high. The abbreviations k, m, b, and t work out for a good while and are more user-friendly than engineering, but now numbers are starting to get into the quadrillions and quintillions, and will display things like "9,999t". I would like to set up the default behavior of numeral.format() to use the abbreviations for anything below 1 quadrillion, and engineering after.

I imagine it's simple if I have the know-how, but I've just been following guides for a few months and only know a few basics, and I haven't the slightest idea how to do this. Anyone who could help me out or point me in the right direction would be appreciated.

In reply to comments:

numeral.defaultFormat("O,0[.]0a");

is my current default format, and when I am dealing with numbers in the quintillions it'll show, as an example, "249,448,931.3t"

What I want it to do is display any number over 1,000t as something like 1.0e+12 and any number below that using standard abbreviations. I tried something like:

numeral.defaultFormat("O,0[.]0a[e+0]");

but that just went to engineering by default.

Larry
  • 1
  • 1
  • please provide a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) so we can run and test it. your question is so unclear. – Parisa.H.R Oct 19 '21 at 21:05
  • Please provide enough code so others can better understand or reproduce the problem. – Community Oct 20 '21 at 02:49
  • You can define and register your own [custom format](http://numeraljs.com/#custom-formats) with your own formatting function. There you can decide base on the value what to return. – derpirscher Oct 24 '21 at 08:27
  • Thanks. Actually creating a custom format was easier than I thought. It's working well enough now. – Larry Oct 26 '21 at 01:42

0 Answers0