If you find this useful, please consider supporting my work with a donation.
A function that accepts a positive integer (or zero) and returns the English-language description of the number.
npm install @humanwhocodes/number-to-words --save
# or
yarn add @humanwhocodes/number-to-words
Import into your Node.js project:
// CommonJS
const { numberToWords } = require("@humanwhocodes/number-to-words");
// ESM
import { numberToWords } from "@humanwhocodes/number-to-words";
Import into your Deno project:
import { numberToWords } from "https://cdn.skypack.dev/@humanwhocodes/number-to-words?dts";
It's recommended to import the minified version to save bandwidth:
import { numberToWords } from "https://cdn.skypack.dev/@humanwhocodes/number-to-words?min";
However, you can also import the unminified version for debugging purposes:
import { numberToWords } from "https://cdn.skypack.dev/@humanwhocodes/number-to-words";
After importing, pass any positive integer or zero to numberToWords()
:
console.log(numberToWords(0)); // "zero"
console.log(numberToWords(10)); // "ten"
console.log(numberToWords(524)); // "five hundred twenty-four"
The numberToWords()
function works up to 999 trillion. If you need larger numbers then that, I envy you.
- Fork the repository
- Clone your fork
- Run
npm install
to setup dependencies - Run
npm test
to run tests
Apache 2.0