Translating the Cardinal Numerals to Words

Well, I see your point, and I can make some changes, but you may not have considered this fact: the word "hundred" is treated differently from words like "thousand" Count how many times you see the word "hundred" in this sample:

INPUT:
123456789123
OUTPUT:
One Hundred Twenty Three Billion Four Hundred Fifty Six Million Seven Hundred Eighty Nine Thousand One Hundred Twenty Three

You see, the word "Hundred" is special because it can occur many, many times. Whereas the word "million" can appear only once.

1 Like

Don't do that until I update my macro. I can make it MUCH EASIER if you wait for an update. I'll try to update my macro now. It will take a minimum of 10 minutes, but if it takes longer than 20 minutes, you will have to wait until tomorrow.

1 Like

Right. I didn't notice that "hundred" is a special number. Thanks

Okay I just updated it and it seems to be working. Let me test it for another minute then I'll upload it here. Here it is. It will be much easier for you to edit. I can't remember if you wanted the last line in this macro or not, so you can remove it if you don't need it.

It's a new version that will make it easier for you to edit the variables right at the front of the macro. I could do even better things to make it support multiple languages at the same time, but that would take an hour.

Cardinals [text].kmmacros (25 KB)

It is ok. You don't have to worry about the translation. You can simply write a little comment to indicate that these boxes are up for translation.

  • I hope you now know why I want "tens one" rather than "eleven". Most languages use that method. The number of language that use "twelve" kind of method rather "tens two" is smaller.

Okay, well, there it is for today. It should meet your needs. But I don't mind adding support for multiple languages at the same time if you want. Let me know tomorrow. I'm nearly done for today.

Thank you so much. You made my day!

how can I keep the original numbers along side their interpretations as follows?

[1241](one thousand two hundred forty one)

I think so. Let me look at my macro again. Give me a few minutes.

What you are asking for may be a little tricky. For example by macro converts in stages, like this:

Easy as 1, then 2, then 3.
Easy as one, then 2 then 3.
Easy as one, then two, then three

So you will notice that in each stage the first number in the string is the one that gets converted in the main loop. By doing it your way, I think I can do it, but I have to think for an extra 15 minutes.

1 Like

Yes, I understand bit. you have integrated the processing into the Part 1 variable. I was trying to keep the original number into a named clipboard, and then concatenate with the results of the Part 2 variable. But, your method is pretty advanced: cannot get my head around it.

I'm getting close to solving one half of your request. The half that keeps a copy of the original number in brackets. That will probably help you a lot. I'm not sure yet if I've solved the second half, which is putting the spelled out words in parentheses.

The problem is that my macro is using the source string as its work area instead of creating other variables. So my macro doesn't remember where the word-number started. I think I have a solution, but I'm not very good with regex and so it's taking me longer than I thought. I think it will take me at least an hour more.

Instead of putting the number in square brackets, which are a pain to work with, I'll try a simpler character like this:

I am 3 years old

Would convert to:

I am =3= three years old.

That would still meet your purpose, I guess.

The good news: I was able to keep the number as a copy in the answer. But I'm still working on the brackets.

MORE good news: I was able to get the brackets to work around the number. Let me decide if it's possible to put parentheses around the word-number, or maybe this will be all I can do.

1 Like

Okay, here's a modified version which will put brackets around the number and also keep a copy of the number for example:

INPUT:
alpha 12 beta 345 gamma 5678 delta
OUTPUT:
alpha Tens Two [12] beta Three Hundred Forty Five [345] gamma Five Thousand Six Hundred Seventy Eight [5678] delta

This is CLOSE to what you asked for, but not quite. First, I don't have parentheses around the word-numbers. Second, the digits FOLLOW the word-number instead of PRECEDE it. I'm not sure if this will meet your needs, but for today it's the best I can do. However I'm willing to consider doing more tomorrow.

I will upload my macro here, in a few seconds:...

Cardinals [text] Macro (v10.0.2)

Cardinals [text].kmmacros (32 KB)

Once again, you are free to delete the final action, which displays the output in a window. Also, I think I coloured the new actions in red, although I may have neglected to colour some.

If I had understood your requirements better from the beginning, this macro wouldn't be so complicated. Right now I'm "hacking" the macro to make it work for your change requests. But if I started from scratch, it would be much cleaner. That's how it is when you write software.

P.S. You are using other languages. I don't know how that may effect the macro because other languages may use other character sets and I did not test any version of my macro with different character sets.

1 Like

Wow, the shell script is crazy complicated.
Thank you so much. You have done the hard part.

And, putting parentheses around the word numbers is simple. I can put the numbers in these parentheses before your macro gets executed.

12_16_21 at 01.07.17PM

Good catch. I'm rather embarrassed I didn't think of that.

1 Like

Nothing to be embarrassed man. You are a brilliant programmer.

Thanks for the kind words.

There is a very small bug in my program that I want to tell you about. If your text that you want to process already contains the letters "xx" in a row, perhaps the word "Exxon" for example, you will probably get a little mistake in the output. You could fix this by replacing my "xx" characters in my macro with "~~" or something else that your text will never use. This approach of mine is a bit of a hack but it was the easiest way to modify my macro for your requirement. If I wrote my macro from scratch now, I would find a way to remove the need for that hack. But if you are still using the macro after a few months, I will be happy to rewrite it for you.

1 Like