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
-
- if we are in the UK and its the last digit-group, we add the add the word âandâ
- if D2 is 1 (ie its a âteensâ value), look up the word in Units using 11+D3 (Eleven, Twelve, Thirteen, âŚ)
- 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
-
- if the user wants commas; use Join(â, â) otherwise Join(â â)
- if the user wants All-Capitals; use Upper() on the whole text.