View Full Version : code to read a number and display it in words
miketallica
09-03-2009, 02:16 PM
i have a document that has a dollar amount and right next it it has the same dollar amount written in words. is there a code that will take the value of the dollar amount and covert it into words.
i am using word 07 but i always save in 03' format
also i need both items to be displayed the dollar amount then the dollar amount spelled out.
macropod
09-03-2009, 04:31 PM
You could do this with a bookmark and a bit of field coding. For example, if you bookmark the value with a bookmark named 'Val', you could use a field coded as:
{=Val \* DollarText}
where the field braces (ie '{}') are created via Ctrl-F9 to represent the value in a text form.
fumei
09-04-2009, 02:50 PM
Could you clarify what EXACTLY are your requirements?
Are you asking about something that will take a whole document with, say, 100 examples of dollar amounts ( $123. $3789.....) and insert the text equivalent beside each one?
$123 One Hundred and Twenty Three
$3789 Three Thousand Seven Hundred and Eighty Nine
Do you want each text equivalent to be capitalized like that? Capitalized at all? Capitalized for all words? Capitalized only for the start?
$123 One Hundred And Twenty Three ???
$123 one hundred and twenty three ???
$123 One hundred and twenty three ???
NOTE: macropod's suggestion is valid. For a bookmarked $123, the result (in the field) looks like:
"one hundred twenty three and 00/100"
macropod, I have never used that before. Cute.
You would have to bookmark every instance of your $xxxx with a unique name though.
macropod
09-04-2009, 03:15 PM
Hi all,
A more sophisticated approach is to use a compund field coded as:
{QUOTE "{=INT(Val) \* CardText} dollars{IF{=MOD(Val,1) \# 0.00}> 0 " and {=MOD(Val,1)*100 \# 0 \* CardText} cents"}"}
or even:
{QUOTE "{=INT(Val) \* CardText} dollar{=INT(Val)-1 \# "s;s;"}{IF{=MOD(Val,1) \# 0.00}> 0 " and {=MOD(Val,1)*100 \# 0 \* CardText} cents"}"}.
For $123.03, this would return "one hundred twenty-three dollars and three cents".
Note: The field brace pairs (ie '{ }') for the above example are created via Ctrl-F9 - you can't simply type them or copy & paste them from this message.
As fumei observed, each value would need its own bookmark although, if you're using a table, you can use cell references instead.
fumei
09-04-2009, 03:20 PM
{QUOTE "{=INT(Val) \* CardText } dollars{IF{=MOD(Val,1) \# 0.00}> 0 " and {=MOD(Val,1)*100 \# 0 \* CardText } cents"}"}
....aaaaaaaggghh
<runs away in panic>
You have my awe and respect sir.
miketallica
09-17-2009, 04:08 PM
macropod,
is it possible to display it in all caps?
macropod
09-18-2009, 01:09 AM
macropod,
is it possible to display it in all caps?
Yes, and it's quite easy to do, all you need to do is to add the '\* Upper' switch before the final '}'
BTW, this (and all the other field switches) is fully documented in Word's Help file
any idea why i get this response when i use your code macropod? error unknown switch argument
macropod
11-06-2010, 11:04 PM
any idea why i get this response when i use your code macropod? error unknown switch argumentMaybe because you didn't input the code correctly (since the message relates to a switch, I'd suggest looking at your field switched first!).
i guess i dont understand what a switch is then. all im doing is inserting a form field changing the format so it display's a number formated as a currency and calculate on exit and then right below it i have a ref field (F9) with this code in it.
{QUOTE "{=INT(Val) \* CardText} dollar{=INT(Val)-1 \# "s;s;"}{IF{=MOD(Val,1) \# 0.00}> 0 " and {=MOD(Val,1)*100 \# 0 \* CardText} cents"}"}
but then i get that error.
nevermind! i figured it out. i had to type the code and insert the field braces using (F9) instead of just copying and pasting the code in to 1 set of field braces.
fumei
11-09-2010, 01:01 PM
As macropod mentioned: "Note: The field brace pairs (ie '{ }') for the above example are created via Ctrl-F9 - you can't simply type them or copy & paste them from this message."
ALL use of brackets in field codes must be inserted with Ctrl-F9.
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.