Large dollar amount switch

T

Todd K.

In one of my merge documents, I use the \*DollarText field switch to format
the dollar amount in words. It has worked fine until now, but we just got a
dollar amount over $1 million and I'm getting an error because the number is
too high. Is there a fix for this?
 
P

Peter Jamieson

In the U.S. you can probably use

{ SET x { MERGEFIELD mylargenumber }



}{ SET r { =MOD(x,1000000) }
}{ SET m { =INT(x-r)/1000000)) }
}{ IF { m } = 0 "" "{ m \*Cardtext } million }" }{ r \Cardtext }

to go a bit larger. You might need to check the calculations better than I
have.

But you can modify the technique anyway to separate out each digit and
convert it to a word.

Peter Jamieson
 
T

Todd K.

Do I paste all of this into the Mergefield or is this code I have to set up
elsewhere?
 
P

Peter Jamieson

it would replace whatever merge field codes you are using now in your Word
document.

In essence, enter the {} pairs into your document using ctrl-F9. Type
everything else in the usual way. Use Alt-F9 to toggle between "field codes"
view and "field results" view. Select the field and press F9 to update the
results.

Peter Jamieson
 
T

Todd K.

I tried it and I'm getting a result of 0.0, but I noticed two inconsistencies
in your code:
1) you have one too many right brackets "}"
2) on your "SET m" line, there are two closing brackets without opening
brackets "))"
 
D

Doug Robbins - Word MVP

The correct field construction is:

{ SET x { MERGEFIELD mylargenumber }}{ SET r { =MOD(x,1000000) }}
{ SET m { =INT((x-r)/1000000) }}
{ IF { m } = 0 "" "{ m \*Cardtext } million "}{ r \Cardtext }


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
P

Peter Jamieson

Yes, there should also be a * before the second "Cardtext". Try:

{ SET x { MERGEFIELD mylargenumber }
}{ SET r { =MOD(x,1000000) }
}{ SET m { =INT((x-r)/1000000)) }
}{ IF { m } = 0 "" "{ m \*Cardtext } million " }{ r \*Cardtext }

Other than that, it seems OK here - what values do you have in your
"mylargenumber" ?

What is the result of { x } ?

Peter Jamieson
 
G

Graham Mayor

It is very easy to make minor mistakes in transposing fields to text strings
but what I suspect Peter really meant was

{ SET x { Mergefield MyLargeNumber }
}{ SET r { =MOD(x,1000000) }
}{ SET m { =INT((x-r)/1000000) }
}{ IF{ m } = 0 "{=INT({ r })\*Cardtext }" "{ =INT({ m }) \*Cardtext }
million " }


This works for me (for integers). To aid the copying of field construction
to text use the macro at http://www.gmayor.com/export_field.htm. That way
you don't get the mistakes ;)

If you have decimals with the numbers (or these are currency amounts) then
further calculations will be required.- see the section formatting cash
amounts in words at http://www.gmayor.com/formatting_word_fields.htm

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
T

Todd K.

Wow, thank you all so much. I actually made a couple of other changes, as
this is for dollars and needed to be in all capitals, so my final code looks
like this:

{ SET x { MERGEFIELD mylargenumber }
}{ SET r { =MOD(x,1000000) }
}{ SET m { =INT((x-r)/1000000) }
}{ IF { m } = 0 "" "{ m \*Cardtext\*Upper } MILLION" }{ r
\*Dollartext\*Upper }

But it works great. Kudos to you.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top