Format Dollar Amounts

From HotDocs Wiki

Jump to: navigation, search

When working with dollar amounts, you can use various formats to merge the answers in your template. For example, if you use the $9,999.00 format, possible results are $1.99, $50.00, and $12,999.75. On the other hand, using the Nine Dollars and Twelve Cents format with the same numbers would produce One Dollar and Ninety-Nine Cents, Fifty Dollars and No Cents, and Twelve Thousand Nine Hundred Ninety-Nine Dollars and Seventy-Five Cents.

Most dollar amount formats can be applied by assigning default or field-specific formats to variables. The following list contains examples of formats you can use as is or modify to meet your needs:


Format Value Result
Nine Dollars 12.00

10.75

Twelve Dollars

Ten Dollars

Nine Dollars and Twelve Cents 12.00

10.75

Twelve Dollars and No Cents

Ten Dollars and Seventy-Five Cents

Nine Dollars and Zero Cents 12.00

10.75

Twelve Dollars and Zero Cents

Ten Dollars and Seventy-Five Cents

Nine Dollars and 9/100 12.00

10.75

Twelve Dollars and 0/100

Ten Dollars and 75/100


Sometimes, there is no way to use a single number format to format a dollar amount exactly as you would like. For example, if you do not want to include and no cents for whole numbers, you must use the Nine Dollars format. However, if the user enters a number that includes cents, this format would truncate the cents. Instead, you can use a Computation variable to analyze a number and apply the correct format depending on how the user answers the question.

The first example script shows how to omit and no cents for whole dollar amounts and include the text for other amounts. Specifically, the computation compares the actual value of a Number variable against its truncated value. If the values are equal, HotDocs uses the Nine Dollars format. Otherwise, it uses the Nine Dollars and Twelve Cents format.

The second example shows how you can substitute the word No for a zero (0) if there are no cents, but otherwise use the numbers. For example, when writing a check, you may want the amount to appear as Five Dollars and No/100 or Five Dollars and 75/100, but not Five Dollars and 0/100.

Example

//Example 1: Format the amount with or without "and Twelve Cents."
""
IF Num Var = TRUNCATE( Num Var, 0 )
  FORMAT( Num Var, "Nine Dollars" )
ELSE 
  FORMAT( Num Var, "Nine Dollars and Twelve Cents" )
END IF
 
//Example 2: Format the amount with digits or the word "No" for cents.
""
IF Num Var = TRUNCATE( Num Var, 0 )
  FORMAT( Num Var, "Nine Dollars and No" ) + "/100"
ELSE 
  FORMAT( Num Var, "Nine Dollars and 9/100" )
END IF
Num Var Any Number variable with two decimal places, representing a dollar amount.