Crystal Reports XI Release 2  

Arithmetic Operators (Basic Syntax)

Arithmetic operators are used to combine numbers, numeric variables, numeric fields and numeric functions to get another number.

The arithmetic operators are addition (+), subtraction (-), multiplication (*), division (/), integer division (\), modulus (Mod), negation (-) and exponentiation (^).

Examples

'Outstanding preferred stock as a percent of
'common stock
formula = ({Financials.Preferred Stock} / _
           {Financials.Common Stock}) * 100
'The square root of 9, Sqr(9), is 3.
'The formula returns 17.
formula =  7 + 2 * 3 - 2 + Sqr(6 + 3) * Len("up")

Order of Precedence

In general, the program evaluates expressions in the following order:

The arithmetic operators in Crystal Reports have the same order of precedence as in Visual Basic. Here is the list, from highest precedence to lowest:

Example

Multiplication and division are performed first from left to right. Then addition and subtraction are performed. For example, 5 + 10 * 3 = 5 + 30 = 35.

You can change this order of precedence by using parentheses. For example, (5 + 10) * 3 = 15 * 3 = 45. If you are unsure of the order of precedence, it is a good idea to clarify your intentions with parentheses.

See Also

Operators (Basic Syntax) | Performing Report Calculations