DIV

Use the DIV script function to divide one value by another and return the result as a 16-digit alphanumeric string with leading zeros.

Syntax

DIV (Operand1, Operand2)

Parameters

  • DIV
    Divides Operand1 by Operand2
    Return code: result of the division

  • Operand1
    First expression
    Format: script literal, script variable or number specified without quotation marks

  • Operand2
    Second expression
    Must not be zero
    Format: script literal, script variable or number specified without quotation marks

Notes:

  • Ensure that the values lie within the allowed range for the declared data types of your script variables. The data type of the result is decisive, not the data type of the operand. Not all data types support negative values and decimals. Negative values result in an error if the variable is not data type float. If the data type of the variable does not allow decimals, any decimals in your result are truncated. For more information, see Script Variable Data Types.
  • Results are returned in the default 16-digit format, with leading zeros. Floating-point numbers also include 16 decimal places. If negative numbers are supported, an algebraic sign (+ or -) is used as the first character.
  • If the result is a floating-point number and the target variable is data type signed or unsigned, the decimals are rounded up or down to the nearest whole number.

Tip: You can remove leading zeros and otherwise edit the format of results with the FORMAT script function.

Examples

The following example passes the division result (5) to a script variable. The examples uses variables for both operands.

:SET &OP1# = '100'
:
SET &OP2# = '20'
:
SET &RESULT# = DIV(&OP1#,&OP2#)

If the data type of the target variable is not float, decimal places are rounded up or down to the nearest whole number. In the following example, the value stored in the result variable is rounded down to 0:

:DEFINE &RESULT#, unsigned
:
SET &RESULT# = DIV(10,30)

The following script divides floating-point numbers, and prints the result in the activation report:

:DEFINE &RESULT#,float
:SET &RESULT#DIV(-9,-2.25)
:P &RESULT#

The result in the activation report would look like this:

U0020408 +0000000000000004.0000000000000000

The following example performs a division using an arithmetic expression:

:SET &DIVIDE# = 10 / 2
:
P &DIVIDE#

The result in the activation report would look like this:

U0020408 0000000000000005

See also: