Number to words template

  • HTML
  • JavaScript

Write any number out in words, as an ordinal and digit by digit, for cheques and invoices.

A plain HTML and JavaScript app that writes numbers out in words. Enter any number, including decimals, and get it in words, as an ordinal like one millionth, digit by digit, and with the part after the decimal point spelled out. Use it for cheques, invoices and legal documents, or for reading numbers aloud.

The number to words app running

What it does

Words and ordinals
Returns both one thousand and one thousandth, so it fits amounts and positions.
Decimals too
Spells out the digits after the decimal point, for amounts and measurements.
One file
The whole page is a single HTML file with its styles and script inside.
Keeps your key private
The page calls a Vercel function in api/, which holds the key, checks the input and limits each visitor to 10 conversions a minute.
Runs locally in one command
npm run dev serves the page and runs the api/ functions together, the same way Vercel does, with no CLI to install.

How it works

The Vercel function: it checks the number and calls Number to Words.

api/words.js
import { guard, callApi, respond, fail } from '../lib/apiverve.js';

// Up to 15 digits, an optional minus sign and up to 6 decimal places.
const NUMBER = /^-?\d{1,15}(\.\d{1,6})?$/;

/** GET /api/words?number=1234.5: the number written out in words, as an ordinal, and digit by digit. */
export async function GET(request) {
  const blocked = guard(request);
  if (blocked) return blocked;

  const number = (new URL(request.url).searchParams.get('number') || '').replace(/,/g, '').trim();
  if (!NUMBER.test(number)) return fail('Enter a number with up to 15 digits and 6 decimal places');

  return respond(() => callApi('numbertowords', { query: { number } }));
}

See the whole file on GitHub

Deploy it

  1. Get a free API key

    The free plan includes 200 credits a month, no card needed. Create your key.

  2. Deploy it

    Click Deploy to Vercel. Vercel copies the repo to your GitHub account and asks for APIVERVE_API_KEY: paste your key there.

  3. Open your app

    Vercel builds it and gives you a live URL, usually in about a minute. Every push to the repo redeploys it.

Try the Number to Words API — the call this template makes

Request
GETapi.apiverve.com/v1/numbertowords?number=975.07
Query parameters
Verification
Format

No key required to try it. Get a key to use it in your app.

Example
{
  "status": "ok",
  "error": null,
  "data": {
    "number": 975.07,
    "words": "nine hundred seventy-five point zero seven",
    "ordinal": "nine hundred seventy-fifth point zero seven",
    "numberOfDigits_numeric": 3,
    "numberOfDigits_words": "three",
    "eachNumber": [
      "nine",
      "seven",
      "five"
    ],
    "afterDecimal": {
      "number": "07",
      "words": [
        "zero",
        "seven"
      ],
      "numberOfDigits_numeric": 2,
      "numberOfDigits_words": "two"
    },
    "locale": "en-US"
  }
}

Build your own with Number to Words. Start with 200 free credits. One key unlocks all 300+ APIs.

Explore the catalog

300+ APIs on the same key and the same response shape.

Browse all APIs