Software

General discussion

Locked

Convert a numeric value into English word

By ·
how can i convert a numeric value into English words in Microsoft Word?

i am using one of the automated word invoice templates.

This conversation is currently closed to new comments.

Thread display: Collapse - | Expand +

Collapse -
by In reply to Convert a numeric value i ...

Hmm, interesting I like the idea. You are going to have to build a function(s) to do this. Hopefully there is a maximum number you expect and it's fairly low becuase building this into the millions would get complex.

Something like this would have to exist for computer speech software. Whether it would go to print instead of speech would be another question. Microsoft has a speech SDK you might run a search on MSDN (www.msdn.microsoft.com)

On to some logic.

Step one would be determining if the number is 0-9, 10 - 99, 100 - 999, etc.

Step Two
Take the number 1229 and take it apart in a loop and then take each part through logic that would result in
One thousand two hundred twenty-nine

Possibly build a table with word number equivalents like 1 to ninety-nine, along with hundred, thousand, million, etc. Everything else is pretty much concatenating values.

strDemo = "One" & " " & "thousand"
strDemo = One thousand

strDemo2 = "Two" & " " & "million" & " " & "Nine" & " " & "Hundred" & "Nine"

A combination of a select case with some nested loops might work this out.

I might give this a shot this weekend so I may have more thoughts later. :)

Mark

Collapse -
by In reply to Convert a numeric value i ...

OK,
You will have to convert each number (0-9) into its ASCII equivalent. For instance, the ASCII code for "A" is 65. This is difficult, because, unless you provide for, say, "take the number 2 digits at a time," you will only be able to get 10 characters (one for each digit). Since the English alphabet requires 2 digits per letter in ASCII (American Standard Code for Information Interchange), you probably want to use Unicode.
So search the web for "Unicode representations in numerical values." The Unicode is 64 bit versus ASCII which is 8 bit. If you use 1 digit, you get symbols like "! @ #" etc.
So for regular ASCII you will have to take 2 digits at a time for English. You will have to create a "macro" written in C or C++. Also, pairs like "09" won't convert into an English letter.
So your number can't begin with certain digits. Like, "65 66 67 68" is ABCD. You would have to provide error checking that would say, "this number doesn't have any letters in it."
So:
1) Does the numeric string translate into letters ?
2) Are the letters grouped in 2s or 3s ? (some letters require 3 digits)
First, create a macro in C or C++, like
#include <iostream>
main()
{
cout << "This is a sentence";
}
then get Word to substitute it whenever it sees a certain symbol (like ^).
Then modify it :
if (one digit represents an ASCII character)
then (print that character)
else
{
if (2 digits represent an ASCII character)
print that character
}
Have fun with this one. First, learn how to make macros in C or C++; then, learn how to examine each number, and when a character is valid, move on to the next number, etc.
Tricky !!
John

Collapse -
by In reply to Convert a numeric value i ...

Believe it or not, it's easier to do it in Word than it is in Excel or Access.

http://www.klippert.com/TCC/Blog/2004_07_01_archive.html#109094236113688090

Word can format numbers in several ways when they are represented by field codes. The = field code is one choice.

Press Ctrl-F9 to insert a pair of field-code delimiters, which resemble boldface curly brackets {}. (The brackets can not be entered directly from the keyboard).

Between the field-code delimiters, enter = followed by the number. Then append the DollarText field switch. The result should look like this:

{=34,582.13 \*DollarText \*Firstcap}

Right-click on the field and choose Update Field. You should now see the number spelled out in words:

Thirty-four thousand five hundred eighty-two dollars and 13/100.

Word provides some other numeric field codes. Here are a few of the more useful ones:

{=42 \*CardText} ? forty-two

{=42 \*OrdText} ? forty-second

{=42 \*Ordinal} ? 42nd

{=42 \*ROMAN} ? XLII

Collapse -
by In reply to Convert a numeric value i ...

Nice work on your copy and paste skills, too bad you got busted.

Im not saying who, but if your going to steal information from someone elses work, do it at your home and offline.

Neil J. Rubenking
Page Source:
http://www.pcmag.com/article2/0,1759,1367932,00.asp

Unfortunately, a responce has been simply cut and pasted as a resolution to this issue.

Please respect others work and do not award credits to the guilty.

Regards,

Related Discussions

• 1

• 3

Which sofware for our company?

niclashenriksson ·

• 0

vertage64 ·

• 2

• 1

estyne ·