# 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.

Respect,
Max

2 Likes

Very cool!

A small bug currently

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

HOW IT WORKS

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.

1 Like

@Bill_French

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.

max

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.

2 Likes

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.

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?

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 coderDojo.com, 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.

integers

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.

1 Like