# Formulas

Formulas are objects that are computed at runtime, which allow you to manipulate field data by performing calculations on it. They control the data that will be displayed, and can even create new data not directly available from the database.

A formula is a symbolic statement of the manipulations that are to be performed on certain data before it is printed onto your report. For example, if your report contains an @Sales field and an @Cost field, and you want to create an @GrossProfit formula, you can designate its value as @Sales - @Cost. @GrossProfit is a simple formula that tells JReport to subtract the value of the @Cost field from the value of the @Sales field, and then to print the result. Formulas can be used to calculate numeric values, compare one value to another and select alternative actions based on the comparison. Also, they can be used to join multiple text strings into a single string.

JReport provides a number of built-in functions for building formulas. It provides user-defined formula (UDF) functions that allow you to design formula functions according to your requirements. Generally, formulas can be used to:

- calculate information you cannot directly obtain from database data fields.
- compare data.
- join text with data.
- convert data from one form to another.
- enhance formatting options with text strings.
- do other things that customize your reports.

The following are some specific topics about JReport formulas:

- Creating a formula
- Formula examples
- User-defined formula functions
- DBArray in formulas
- Using formulas in reports
- Using formulas to control object properties

See an example: The SampleComponents catalog, included with JReport Designer, contains reports that have examples of how formulas could be used in a report. For the example, open `<install_root>\Demo\Reports\SampleComponents\UsingFormula.cls`.