Given both that the question which created the numeraljs directly links to the Numeral.js site, and that 5 of the 9 questions tagged numeraljs were also tagged numeral.js, I went ahead and merged the two tags with the .js version as the parent tag.

I also created a synonym directing from numeraljs to numeral.js which will prevent someone from creating a dot-less version in future (since it already exists).

If someone is knowledgeable and so inclined to create a better tag wiki excerpt which provides actual usage guidance and a tag wiki which doesn't plagiarise the documentation that'd probably be of value as well.

Answer from Henry Ecker on Stack Overflow
🌐
Numeraljs
numeraljs.com
Numeral.js
A javascript library for formatting and manipulating numbers.
🌐
GitHub
github.com › adamwdraper › Numeral-js
GitHub - adamwdraper/Numeral-js: A javascript library for formatting and manipulating numbers. · GitHub
A javascript library for formatting and manipulating numbers. - adamwdraper/Numeral-js
Starred by 9.7K users
Forked by 913 users
Languages   JavaScript
🌐
Medium
anurag-sachdeva.medium.com › taking-your-numerical-formatting-to-the-next-level-with-numeral-js-a-developers-guide-b1f94fcd4d7a
Taking Your Numerical Formatting to the Next Level with Numeral.js: A Developer’s Guide
April 9, 2023 - Are you tired of struggling with formatting and displaying numerical data in your web applications? Look no further than Numeral.js, a lightweight and powerful JavaScript library that makes formatting and manipulating numbers a breeze.
🌐
npm
npmjs.com › package › numeral
numeral - npm
Format and manipulate numbers.. Latest version: 2.0.6, last published: 9 years ago. Start using numeral in your project by running `npm i numeral`. There are 3467 other projects in the npm registry using numeral.
      » npm install numeral
    
Published   Mar 27, 2017
Version   2.0.6
Author   Adam Draper
🌐
npm
npmjs.com › package › @elastic › numeral
@elastic/numeral - npm
May 6, 2021 - A javascript library for formatting and manipulating numbers. Forked from https://github.com/adamwdraper/Numeral-js
      » npm install @elastic/numeral
    
Published   May 06, 2021
Version   2.5.1
🌐
cdnjs
cdnjs.com › home › libraries › numeral.js › 1.0.3
numeral.js - Libraries - cdnjs - The #1 free and open source CDN built to make life easier for developers
numeral.js · 1.0.3 · Format and manipulate numbers. 8k · GitHub · package · MIT licensed · http://numeraljs.com/ Tags: numeral, number, format, time, money, percentage · Version · 1.0.3 · Loading...
Find elsewhere
🌐
GitHub
github.com › elastic › numeral-js
GitHub - elastic/numeral-js: A javascript library for formatting and manipulating numbers.
A javascript library for formatting and manipulating numbers. - elastic/numeral-js
Starred by 10 users
Forked by 13 users
Languages   JavaScript 100.0% | JavaScript 100.0%
🌐
Elastic
elastic.co › elastic docs › explore and analyze › numeral formatting
Numeral formatting | Elastic Docs
The simplest pattern format is 0, and the default Kibana pattern is 0,0.[000]. The numeral pattern syntax expresses:
🌐
DZone
dzone.com › coding › javascript › format and manipulate numbers with numeral.js
Format and Manipulate Numbers With Numeral.js
May 13, 2017 - I recently found out about Numeral.js, a JavaScript library for formatting and manipulating numbers.
🌐
CodeSandbox
codesandbox.io › s › numeraljs-format-test-venj5
Numeral.js format test - CodeSandbox
January 29, 2020 - Numeral.js format test by lothisoft using numeral
Published   Jan 29, 2020
Author   lothisoft
🌐
npm
npmjs.com › package › numeraljs
numeraljs - npm
September 29, 2015 - Format and manipulate numbers.. Latest version: 1.5.6, last published: 10 years ago. Start using numeraljs in your project by running `npm i numeraljs`. There are 10 other projects in the npm registry using numeraljs.
      » npm install numeraljs
    
Published   Sep 29, 2015
Version   1.5.6
Author   Nico Sap
🌐
SourceForge
sourceforge.net › projects › numeral-js.mirror
Numeral.js download | SourceForge.net
June 29, 2021 - Download Numeral.js for free. A javascript library for formatting and manipulating numbers. You can use Numerals in the browser and in Node.js. Create an instance of a numeral, Numeral takes numbers or strings that it trys to convert into a number.
🌐
Elastic
discuss.elastic.co › elastic stack › kibana
Numeral.js custom format - Kibana - Discuss the Elastic Stack
September 15, 2015 - hi guys. I am trying to figure out this Numeral.js. I want a "." as thousand operator and a "," to round numbers off. Example of my number field: 100000. I want that to look like 1.000,00. Possible?
🌐
Stack Overflow
stackoverflow.com › questions › 62403873 › numeral-formatting-on-amounts
Numeral Formatting on amounts
I use NumeralJS for formatting amounts as below; numeral(unformattedValue).format(amtFormat) Now if the amtFormat is set as "0,0.00", then if the amount is entered as "123.1", I get it as "123.10"...
🌐
Stack Overflow
stackoverflow.com › questions › 69637576 › numeral-js-formatting-extremely-large-numbers
Numeral.js formatting extremely large numbers - Stack Overflow
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
Top answer
1 of 2
1

In this case you will need to use a different format string depending on the size of the original number. It looks like you have the following cases:

  • If the number is under 1000, return the same number in long format but with at most two decimal places.
  • If the number is between 1000-10,000, return the same number in long format with no decimal places.
  • If the number is between 10,000-1,000,000, return the same number in shorthand format, with at most one decimal place.
  • If the number is larger than 1,000,000, return the same number in shorthand format, with at most two decimal places.

For each of these cases you will need a different format string. You can do that by comparing the number to each threshold and setting the format string depending on its size.


function formatValue(value, shorthandFormat = true, shorthandLength = 5) {
  if (value === undefined || value === null) return '?';

  let valueString = value.toString();
  if (valueString.trim() === '') return '';

  let numeralValue = numeral(value)

  // Note the format changes depending on how large the value is.
  let formatter = "0[.][00]" // Default formatter: returns the same number with at most, two decimals.
  if (value > 1000) formatter = "0" // Over 1000: remove any decimal part.
  if (value > 10000) formatter = "0.[0]a" // Over 10000: use shorthand with at most, one decimal.
  if (value > 1000000) formatter = "0.[00]a" // Over 1000000: use shorthand with at most, two decimals.

  let formattedValue = numeralValue.format(formatter);

  return formattedValue;
}

const tests = [
  // Small numbers contain at most, two decimals.
  [0, "0"],
  [1, "1"],
  [1.1, "1.1"],
  [1.11, "1.11"],
  [1.115, "1.12"],
  [11.1, "11.1"],
  [11.11, "11.11"],
  [16.75, "16.75"],
  [675, "675"],
  [675.5, "675.5"],
  [675.55, "675.55"],
  
  // Numbers between one-thousand and ten-thousand may not contain decimals.
  [6700.05, "6700"],
  [2522.25, "2522"],
  [6000, "6000"],
 
  // Numbers between ten-thousand and one-million should use shorthand, with at most one decimal.
  [67500.89, "67.5k"],
  [67530.85, "67.5k"],
  [210500, "210.5k"],
  [210000, "210k"],
  
  // Numbers greater than one-million should use shortand, with at most two decimals.
  [2120000, "2.12m"],
  [6750000, "6.75m"],  
  [2000000, "2m"],
  [2100000, "2.1m"],
  [2010000, "2.01m"],
  [2001000, "2m"],
]

tests.forEach(([input, output]) => console.log(`${formatValue(input) === output ? "PASS" : "FAIL"}: ${input} --> ${formatValue(input)}. Expected: ${output}`));
<script src="https://cdnjs.cloudflare.com/ajax/libs/numeral.js/2.0.6/numeral.min.js"></script>

Note: The test for number 67500.89 was changed to expect 67.5k as the result, since 6.7k seemed to be a typo.

2 of 2
0

Here is code example from a number shorthand formatter I built awhile ago that does exactly what you want.

function numberIntoString({
  value,
  decimals,
}) {
  value = value.toString().replace(/[^0-9.]/g, "");
  let si = [
    { value: 1e3, symbol: "K" },
    { value: 1e6, symbol: "M" },
    { value: 1e9, symbol: "B" },
    { value: 1e12, symbol: "T" },
  ];
  let i;
  for (i = si.length - 1; i > 0; i--) {
    if (value >= si[i].value) {
      break;
    }
  }
  return (
    (value / si[i].value)
      .toFixed(decimals)
      .replace(/\.0+$|(\.[0-9]*[1-9])0+$/, "$1") + si[i].symbol
  );
}
🌐
YouTube
youtube.com › watch
A JavaScript library for formatting and manipulating numbers - Numeral.js - YouTube
Check out this light weight JavaScript library used for formatting and manipulating numbers. For example 1,000 to 1k, 1,000,000 to 1m and so on.Library:: htt...
Published   July 18, 2021