Quite often you will want to take a number entered into a field on a form, or calculated using the Rules Wizard or script, and insert it into a document template. However, how the number is entered into the field on the form may not be exactly how you want the number to look in your document template. This is when number formatting comes into play.
Word has a number of built-in number formats, and the good news is that you can use all of them in your document templates with our assembly engine. In order to do this you need to invoke the number ‘switches’ that are an extension to the Word mergefields.
In order to use a format switch in Word for a number you need to adopt the following syntax:
{MERGEFIELD Number_num \SWITCH }
You may also want to apply a numeric format mask to a number inserted into your document template. For information how to do this, read this article.
List of Word number switches
The following is a list of number switches and their results:
\*alphabetic
This switch displays results as alphabetic characters. The result has the same case as the word “alphabetic” in the field code. For example, { MERGEFIELD 2 \* ALPHABETIC } displays B (instead of 2), and { MERGEFIELD 2 \* alphabetic } displays b.
\*Arabic
This switch displays results as Arabic cardinal numerals. For example, { MERGEFIELD 31 \* Arabic } displays 31.
For page numbers only, there is also an ArabicDash format, which displays results as Arabic cardinal numbers surrounded by hyphen characters. For example, { PAGE \* ArabicDash } displays – 31 -.
\* CardText
This switch displays results as cardinal text. The result is formatted in lowercase letters unless you add a format switch to specify a different capitalization. For example, { = SUM(A1:B2) \* CardText } displays ‘seven hundred ninety‘, and { = SUM(A1:B2) \* CardText \* Caps } displays ‘Seven Hundred Ninety‘.
\DollarText
This switch displays results as cardinal text. Word inserts the decimal place and displays the first two decimals (rounded) as Arabic numerators over 100. The result is formatted in lowercase letters unless you add a format switch to specify a different capitalization. For example, { = 9.20 + 5.35 \DollarText \* Upper } displays ‘FOURTEEN AND 55/100‘.
\*OrdText
This switch displays results as ordinal text. The result is formatted in lowercase letters unless you add a format switch to specify a different capitalization. For example, { DATE \@ “d” \* OrdText } displays ‘twenty-first‘, and { DATE \@ “d” \* OrdText \* FirstCap } displays ‘Twenty-first‘.
\*Ordinal
This switch displays results as ordinal Arabic numerals. For example, { DATE \@ “d” \* Ordinal } displays ‘30th‘.
\*Roman
This switch displays results as Roman numerals. The result has the same case as the word “roman” in the field code. For example, { SEQ CHAPTER \* roman } displays ‘xi‘, and { SEQ CHAPTER \* ROMAN } displays ‘XI‘.
\abs
To make a number show as a positive (irrespective of whether the value is negative or positive) you need to include the \abs switch in the mergefield.
\round n
To round a number in a document Template to a number (n) of decimal places, you use the \round n switch as follows:
{ MERGEFIELD Number_num \round 2 } is rounded to 2 decimal places
Comments
0 comments
Article is closed for comments.