# Functions in document templates

Functions can be used when automatically formatting documents using templates. Functions simplify how data is displayed in your documents. For example, you can use formulas to automatically display numbers as words or calculate order costs.

## Contents

## Formulas

To add a formula to a document, use the following syntax: %%%**FORMULA**%%%.

**A FORMULA** is an expression for calculating the value of a field, just like in a calculated field.

Example:

In the example above, data from the "Service" data tag is added to the formula using the corresponding variables. The two values are multiplied, and the result is the value of the total cost of a specific service or product. The TEXT() function formats the value as a human-readable text string.

## Functions

All functions available in document template formulas:

## The SUM function

**SUM()** is a function that adds up all values obtained when calculating a formula. It is applied to each element of a multiplying variable.

For example, say you have a "Service" data tag and you want to calculate the total cost of all services in a document. You would use the following function:

SUM({{DataTag.Service.Cost}})

In order to get the total cost of services provided, you must multiply the cost of the service by the number of times it was ordered. Here's the formula you should use in your document:

SUM({{DataTag.Service.Cost}}*{{DataTag.Service.Quantity}}))

Note that the SUM() function can contain any formula made up of functions.

## The NUMBERASWORDS function

This is a function that returns a number as words. Only the integer part of the number is written out.

Format:

NUMBERASWORDS(number; Output; "language")

Where:

**number**is a number or formula**Output:**- 0 - regular output
- 1 - capitalized output

**language**- (empty) — language of user creating document is used
**ru**— Russian**en**— English**uk**— Ukrainian

For example, to display a number as words in a document, use the following function:

NUMBERASWORDS(SUM({{DataTag.Service.Cost}}*{{DataTag.Service.Quantity}}); 2; "en")

## The FRACTIONALPART function

This function displays the fractional part of a number. You can specify the number of digits after the decimal point you would like to see.

Format:

FRACTIONALPART(number; NumberOfDigitsAfterDecimal)

For example, to output the number of cents for the cost of a service in a document, use the following function:

FRACTIONALPART(SUM({{DataTag.Service.Cost}}*{{DataTag.Service.Quantity}}); 2)

This function displays the two digits after the decimal point:

- 176.03 — function returns 3.
- 15.15 — function returns 15.
- 16.156 — function rounds first two decimal points to 16.