Number to Words

For a client, a way to convert an INTEGER to WORDS with options to include/exclude commas, to use either the US or UK syntax, and to have all-caps or proper-case

And we wanted it to be a pure Coda solution, without using a PACK.

It is for writing CHEQUES where the amount must also be written in words (but not the decimal part).

There are lots of examples out there in Javascript, and hugo_assuncao has made a Pack as well.

But this solution is built with a few tables and formulas in Coda, so it can be tailored by our clients in the future.

I will post a full description of how it works later.



Very cool!

A small bug currently :wink:
Screenshot 2023-09-28 at 9.49.33 AM
and “fourty” should be “forty”.

1 Like

Yes, its intended for INTEGERS only - by design (as per client requirement).

Will fix the spelling mistake - thanks


We have 3 lists of words for Scale (Billions, Millions, …), Tens (Twenty, Thirty, …) and Units, which also covers ‘teens’ words (One, Two, Three, … Ten, Eliven, Twelve, Thirteen, …)

1: first we pad-out the number to 12 digits with leading-zeros (this simplifies all that follows)


2: then we divide the 12-digit number into 4 three-digit-gropus in a separate table, one row per group


3: the 3 digit group is divided into separate digits D1, D2 & D3


4: we compute the correct set of words W1 … W5 for each DigitGroup (row) as follows…

5: W1: if D1 is not zero, look up the number-word from the Units table


6: W2: if D1 is not zero, add the word “Hundred” (if in the UK also add “and”)


7: W3: if D2 is more than 1, look up the Tens table for the amount (Twenty, Thirty, … ), otherwise leave blank


8: W4: has 3 parts to its calculation

    1. if we are in the UK and its the last digit-group, we add the add the word “and”
    2. if D2 is 1 (ie its a ‘teens’ value), look up the word in Units using 11+D3 (Eleven, Twelve, Thirteen, …)
    3. otherwise its not a ‘teens’ value, so look up the word in Units using just D3


9: W5: is the ‘Scale’ word, look it up in the Scale table using Row (Billion, Million, Thousand, …)


10: The Words column joins all the words into a single text


11: Finally we join all the words for the rows using the following formatting rules

    1. if the user wants commas; use Join(”, “) otherwise Join(” “)
    2. if the user wants All-Capitals; use Upper() on the whole text.


All that effort compressed into a single AI prompt developed in 45 seconds. What am I missing? I don’t think I’m missing anything. :wink:

1 Like


firstly, we dont (yet) trust AI to do algorithnic stuff correctly 100% of the time.
secondly, use of AI wont pass an audit for an app that WRITES CHEQUES for billions.
thirdly, using tera-flops of remotely hosted GPU resources, to do simple arithmetic? do we reccomend that? in every case? for your tax returns? for your pay-roll? not there yet methinks!

finally, i ENJOYED doing it this way. i am an oil-painter who continues working after the invention of the camera.

my client (the biggest life assurance company in europe) has used LOTS of AI models for decades.
they invest billions on improving their business with AI. and they have learned WHERE it works and where it DOESNT.

their auditors have some strict views on this matter, based on real-world use cases.

some day maybe. not yet.


i dont want to be that grumpy old guy who laments the use of calculators in schools…
i do use copilot a lot. but i check and test its suggestions every time. its comic what it comes up with betimes.


i just read your article on ‘ai first’ and loved it.

text and sentenses and language grammaticaly squishy stuff is where LLMs really do shine, and i wouldnt try to write formulas or code to solve those kind of things any more.

but numerucal, monetary, time-line, or simple counting; todays LLMS fail occasionally with great confidence and authority.

i turned up two hours early for a confetence because chatGPT told me the wrong translation from PST time to EET time. it was a reminder to me to treat LLMs with a grain or two of salt where arithmetic is concerned.

1 Like

I wouldn’t either without a very large test set. Ironically, even the test data set can be constructed with AI and the tests themselves can be fully automated. :wink:

At the outset, this is not arithmetic; it’s strings of numbers (which are well understood by LLMs). I think this is why it works predictably. As to the GPUs, this is a sunk cost and tasks like this are not even a rounding error of a rounding error in the work load that these data centers are already performing. And do you really think that your approach is not spinning up processes in GPUs? :wink:

The philosophical plea doesn’t sway me to consider the vast effort and possible errors that a codified solution will produce. This is the way and increasingly, it will be proven to be the right way.

My sense, though, is that this approach could be 99.9999% deterministic and even when introducing support for localized languages or compliance practices.

CopIlot’s are not designed to be deterministic so that also doesn’t hold sway with me. This solution could be designed to be near perfect.

1 Like

When I first reviewed the process you established, I wondered - what impact (if any) would the infamous Java floating point “bug” have on this algorithm?

1 Like

Thanks for sharing, @Xyzor_Max! As always, you present not solely the solution, but also your thought process and its Coda step-by-step execution. What a lovely way to allow anyone interested to follow along, much appreciated!

1 Like

how did i end up trying to defend a position i dont really espouse?

argh… i HAVE become that grumpy old luddite… oh no!

i teach teenagers to code at the local, and find that nobody can do long division or mental arithmetic anymore.

but so what?

we all have smart phones. google lookup. youtube tutorials. so who cares.

teaching people to code will be anachronistic soon.

your point about the cost of maintaining the code and extending it for other languages is the clincher for me.

so i concede the argument. for this (and similar) use casea.

… … …

what i REALLY want is an AI tool that can watch employees doing office work, and then design and build automated workflows for them, and be able to explain its reasoning along the way.

then i can retire to a paradise island and grow vines.

how about it Codans ???


Oh sorry, you did mention that!

Cool solution

1 Like

LOL You didn’t need to do this so formally. I knew you had pressure from the client and the responsibility to be assuring of perfection.

Well, I have kinda written about that. :wink:

1 Like