js-number-to-word-processor

3.0.4 • Public • Published
The Goal Of JSnumberToWordProcessor Is A Well Formatted Human Readable Number, With It's Corresponding Words.
JSnumberToWordProcessor Is A Pure Vanilla JavaScript Plugin With No Dependencies.

  1. Fixed Display Of Multiple Zeros Greater Than 2 Length.
    • If A Decimal Place Length Greater Than 2 Is Specified, And Its Corresponding Decimal Number Is 0, Application Would Fallback To A 2 Decimal Place Number of (.00)
      e.g
      JSnumberToWordProcessor(26.00000232, 5) would return 26.00 instead of 26.00000
  2. Correct Decimal Place Word With Starting Zeros
    e.g
    JSnumberToWordProcessor(26.00002, 5) Now Returns Twenty-Six (dot) Two tenths Instead Of Twenty-Six (dot) undefined Thousand, and Two hundred-thousandths

Use On repl.it
Use On repl.it
Use On repl.it
// Navigate To https://repl.it/languages/Nodejs#index.js
// On repl.it Call...
 
const JSnumberToWordProcessor = require("js-number-to-word-processor");
 
// Pass In A Single Number-String (with or without a decimal number argument)
JSnumberToWordProcessor("-4783484773.7634656549", 9);
 
// OR An Array Of Numbers
JSnumberToWordProcessor(["6677", "-7674.969", "0.00"]);

HTML Script
HTML Script
HTML Script
<script src="curStrLengthFunc_2.min.js"></script>
<script src="JSnumberToWordProcessor.js"></script>

NPM Installation
NPM Installation
NPM Installation
npm i js-number-to-word-processor

ES5 module:
ES5 module:
ES5 module:
const JSnumberToWordProcessor = require("js-number-to-word-processor");
ES6 module:
import JSnumberToWordProcessor from "js-number-to-word-processor";
AMD loader libraries such as requireJS:
require(["js-number-to-word-processor"], function (num) {
  // Use JSnumberToWordProcessor here in local scope.
});

NOTE <br/ > Always Use BigInteger / BigInt or Number String When Dealing With Big Numbers Above 2^53-1

e.g
877373863274895753n or '877373863274895753'
OR
BigInt(245786743890965998) or '245786743890965998'


Call JSnumberToWordProcessor & PASS In Either A Positive Whole Number, BigInteger, OR Number-String
NOTE <br/ > Always Use BigInteger / BigInt or Number String When Dealing With Big Numbers Above 2^53-1

e.g
877373863274895753n or '877373863274895753'
OR
BigInt(245786743890965998) or '245786743890965998'


Call JSnumberToWordProcessor & PASS In Either A Positive Whole Number, BigInteger, OR Number-String
NOTE <br/ > Always Use BigInteger / BigInt or Number String When Dealing With Big Numbers Above 2^53-1

e.g
877373863274895753n or '877373863274895753'
OR
BigInt(245786743890965998) or '245786743890965998'


Call JSnumberToWordProcessor & PASS In Either A Positive Whole Number, BigInteger, OR Number-String

Always Use BigInteger / BigInt or Number String When Dealing With Big Numbers Above 2^53-1

e.g
877373863274895753n or '877373863274895753'
OR
BigInt(245786743890965998) or '245786743890965998'


Call JSnumberToWordProcessor & PASS In Either A Positive Whole Number, BigInteger, OR Number-String

JSnumberToWordProcessor("987"); // 987: Nine Hundred and Eighty-Seven
JSnumberToWordProcessor(8476787747); // 8,476,787,747: Eight Billion, Four Hundred and Seventy-Six Million, Seven Hundred and Eighty-Seven Thousand, Seven Hundred and Forty-Seven
JSnumberToWordProcessor(5876985876950n); // 5,876,985,876,950: Five Trillion, Eight Hundred and Seventy-Six Billion, Nine Hundred and Eighty-Five Million, Eight Hundred and Seventy-Six Thousand, Nine Hundred and Fifty
JSnumberToWordProcessor(BigInt(6856767875879601367476468) % BigInt(8)); // 0: Zero
PASS An Array Of Positive Whole Number, BigInteger, OR Number-Strings
JSnumberToWordProcessor([
  "6478", // 6,478: Six Thousand, Four Hundred and Seventy-Eight
  579n, // 579: Five Hundred and Seventy-Nine
  "57682587695780", // 57,682,587,695,780: Fifty-Seven Trillion, Six Hundred and Eighty-Two Billion, Five Hundred and Eighty-Seven Million, Six Hundred and Ninety-Five Thousand, Seven Hundred and Eighty
]);
JSnumberToWordProcessor([
  6478 * (55.999865 * -8), // -2,902,137.38: (negative) Two Million, Nine Hundred and Two Thousand, One Hundred and Thirty-Seven (dot) Thirty-Eight hundredths
  579n / ((55n / 11n) * 10n), // 11: Eleven
  579 / ((55 / 11) * 10), // 11.58: Eleven (dot) Fifty-Eight
]);
PASS A Decimal Numbers
JSnumberToWordProcessor(5876.98587695); // 5,876.99: Five Thousand, Eight Hundred and Seventy-Six (dot) Ninety-Nine hundredths
JSnumberToWordProcessor("5876.985876950", 5); // 5,876.98,588: Five Thousand, Eight Hundred and Seventy-Six (dot) Ninety-Eight Thousand, Five Hundred and Eighty-Eight hundred-thousandths
PASS A Negative Numbers
JSnumberToWordProcessor("-876950"); // -876,950: (negative) Eight Hundred and Seventy-Six Thousand, Nine Hundred and Fifty
JSnumberToWordProcessor("-8769.5", 1); // -8,769.50: (negative) Eight Thousand, Seven Hundred and Sixty-Nine (dot) Five tenths
SOLVE Arithmetic Operations
When Solving Arithmetic Calculations (+), Always Pass Arguments As Numbers, OR BigIntegers,
Other Arithmetic Operations Could Be Passed In As A Numbers, BigInteger, OR As A String.
 When Solving Arithmetic Calculations (+), Always Pass Arguments As Numbers, OR BigIntegers, <br />
 Other Arithmetic Operations Could Be Passed In As A Numbers, BigInteger, OR As A String.
JSnumberToWordProcessor(55 / 11); // 5: Five
JSnumberToWordProcessor(55 * 11); // 605: Six Hundred and Five
JSnumberToWordProcessor(555n * 111n); // 61,605: Sixty-One Thousand, Six Hundred and Five
JSnumberToWordProcessor(55 - 11); // 44: Forty-Four
JSnumberToWordProcessor(55 + 11); // 66: Sixty-Six
JSnumberToWordProcessor("55" ** "3"); // 166,375: One Hundred and Sixty-Six Thousand, Three Hundred and Seventy-Five
JSnumberToWordProcessor(55 % 3); // 1: One
JSnumberToWordProcessor(55 + -8); // 47: Forty-Seven
JSnumberToWordProcessor(55.1 / 3 - 8.2); // 10.17: Ten (dot) Seventeen hundredths
JSnumberToWordProcessor(55 * 0.8); // 44: Forty-Four
JSnumberToWordProcessor(5876 / 985876950); // 0.60: Zero (dot) Sixty
Use BigInteger / BigInt
JSnumberToWordProcessor(55n ** 18n); // 21,209,401,372,879,911,350,250,244,140,625: Twenty-One Nonillion, Two Hundred and Nine Octillion, Four Hundred and One Septillion, Three Hundred and Seventy-Two Sextillion, Eight Hundred and Seventy-Nine Quintillion, Nine Hundred and Eleven Quadrillion, Three Hundred and Fifty Trillion, Two Hundred and Fifty Billion, Two Hundred and Forty-Four Million, One Hundred and Forty Thousand, Six Hundred and Twenty-Five
JSnumberToWordProcessor([(BigInt(55) / BigInt(11)) * BigInt(10)]); // 50: Fifty
Define The Decimal Place Length With A Second Number Argument

NOTE: The Second Argument Would Only Be Called On A Decimal Number If The Second Argument Is Greater Than The Decimal Point Length, A Default 2 Decimal Point Would Be Used

Define The Decimal Place Length With A Second Number Argument

NOTE: The Second Argument Would Only Be Called On A Decimal Number If The Second Argument Is Greater Than The Decimal Point Length, A Default 2 Decimal Point Would Be Used

JSnumberToWordProcessor(55.999865 * -8.5, 6); // -475.99,885: (negative) Four Hundred and Seventy-Five (dot) Nine Hundred and Ninety-Eight Thousand, Eight Hundred and Fifty-Three millionths
JSnumberToWordProcessor(
  [
    "55.999858659554367" * "-8.79", // -475.99,885: (negative) Four Hundred and Ninety-Two (dot) Twenty-Three Trillion, Eight Hundred and Seventy-Five Billion, Seven Hundred and Sixty-One Million, Seven Hundred and Forty-Eight Thousand, Two Hundred and Eighty-Six hundred-trillionths
    55.999999 + 8, // 64.00: Sixty-Four
  ],
  14
);
JSnumberToWordProcessor(55.888888 + 8, 5); // 63.88,889: Sixty-Three (dot) Eighty-Eight Thousand, Eight Hundred and Eighty-Nine hundred-thousandths
JSnumberToWordProcessor(55.999999 / 8, 5); // 7.00: Seven
JSnumberToWordProcessor(55.1 - 8.2, 3); // 46.900: Forty-Six (dot) Nine Hundred thousandths
JSnumberToWordProcessor(55.9979865 * -(-8.5), 7); // 475.9,828,853: Four Hundred and Seventy-Five (dot) Nine Million, Eight Hundred and Twenty-Eight Thousand, Eight Hundred and Fifty-Three ten-millionths
JSnumberToWordProcessor(
  [
    -55.999865 * -8.5, // 475.9,988,525: Four Hundred and Seventy-Five (dot) Nine Million, Nine Hundred and Eighty-Eight Thousand, Five Hundred and Twenty-Five ten-millionths
    5 ** 4, // 625: Six Hundred and Twenty-Five
  ],
  7
);
PROCESS Booleans
NOTE: 0 === false && 1 === true
NOTE: 0 === false && 1 === true
JSnumberToWordProcessor(55 > 26); // 1: One
JSnumberToWordProcessor(55 < 26); // 0: Zero
JSnumberToWordProcessor(55 <= 26); // 0: Zero
JSnumberToWordProcessor(55 == "55"); // 1:
JSnumberToWordProcessor(55 === "55"); // 0: Zero
JSnumberToWordProcessor(55 !== "55"); // 1: One


How To Use JSnumberToWordProcessor Plugin In Your Project

  • Install JSnumberToWordProcessor Plugin In Your Project File
    OR
    Download, And Attach curStrLengthFunc_2.min.js & JSnumberToWordProcessor.js Script To Your HTML Document.
  • Ensure You Pass in The Number Argument As A String OR As A BigInter().
    This Is Because JavaScript Has A Number Length Limit Of 2^53-1.
    But If You Would Be Dealing With Numbers Less Than 2^53-1 Length,
    Then Feel Free To Input A Number As Your Argument.
    For Decimal Numbers
    Pass A The Second Argument Which Could either Be A Number Or A String. If No Second Argument Is Passed In For Decimal Numbers Or The Second Argument Is Greater Than The Actual Decimal Number Length, A default Value Of 2 Decimal Number Length Is Used.
    e.g
    JSnumberToWordProcessor('123456.78998765', 5)
    OR
    JSnumberToWordProcessor(['123.98765', '445.556', '68', '8575.7766', '84974'], 3).
  • Alternatively;
    Just Append (n) (Without Parentheses) to The End Of The Number Longer Than 2^53-1
    e.g.
    123456789098765432n
    OR
    [123456789098765433n, BigInt(123456789098765434), 123456789098765434n].
    This Calls The BigInt() Method Which Allows JavaScript To Handle BIG Numbers.
  • Better Still;
    Just Check JSnumberToWordProcessor's index.html & See How It's Been Put To Use
    OR
    Check Proforma Invoice Calculator To See JSnumberToWordProcessor At Work
  • Display The Result In Your Project.

  1. Corrected Application Dismissal Of Starting Zeros After A Decimal Point.
  1. Application Now Handles Decimal Numbers, With Fractions.
    1. For decimal numbers, users can pass in a second argument which would indicate the decimal number length
    2. If a second argument isn't passed in for decimal numbers, a default 2 decimal point would be used
  2. Application Now Handles Negative Numbers.
  3. Application Can Solve Arithmetic Operations and Output The Result In Human Readable Number & Word
  1. Corrected Read Me installation process.
  2. Code Optimized.
  1. Application Can Now Process Numbers Up To "10^33003", Into Human Readable Numbers & Words Based On Conway-Wechsler Numbering System.
  2. Optimized Code For Efficiency (Rewrote Most Part).
  3. Pure Vanilla JS With No Dependencies.
  1. Application Can Now Handle Numbers Larger Than 2^53-1 Up To 10^126.
  2. Spelling Errors Corrected.
  3. Code Refined.

Install From NPM
Install From NPM
Install From NPM
Get Source Code From GitHub
Use Live Site @ JSnumberToWordProcessor
Proforma Invoice Calculator is Another Application Using #JSnumberToWordProcessor



JavaScript Number To Word Processor Is Developed By Saheed Odulaja.
Feel Free To Fork This Repository.
Also Be Kind Enough To Leave A STAR 🌟 As A Mark Of Encouragement 😃.

Package Sidebar

Install

npm i js-number-to-word-processor

Weekly Downloads

0

Version

3.0.4

License

MIT

Unpacked Size

774 kB

Total Files

5

Last publish

Collaborators

  • sidodus