IBM Books

Reference


Math Functions

These functions let you do mathematical calculations.

NLS considerations for math functions: Net.Data displays decimal points in numerical values based on regional settings specified at the Web server under which Net.Data is running. For example, if the decimal point is specified as a comma (,) at the Web server, Net.Data uses the comma to format decimal data. Net.Data uses the following settings to determine which character is used to specify a decimal point:

For OS/390, Windows NT, OS/2, and UNIX operating systems:
The LOCALE under which the Web server executes

For the OS/400 operating system:

The following functions are available for mathematical calculations:

DTW_ADD


AIX HP-UX Linux OS/2 OS/390 OS/400 SCO SUN Win NT
X X X X X X X X X

Purpose

Adds two numbers.

Format

@DTW_ADD(number1, number2, precision, result)

@DTW_ADD(number1, number2, result)

@DTW_rADD(number1, number2, precision)

@DTW_rADD(number1, number2)

Parameters

Table 57. DTW_ADD Parameters

Data Type Parameter Use Description
float number1 IN A variable or literal string representing a number.
float number2 IN A variable or literal string representing a number.
integer precision IN A variable or literal string representing a positive whole number that specifies the precision of the result. The default is 9.
float result OUT A variable that contains the sum of number1 and number2.

Return Codes

Table 58. DTW_ADD Return Codes

Return Code Explanation
-1001 The server could not process a Net.Data request to allocate memory.
1001 An input parameter contained a NULL value.
1002 An input parameter contained a string value which consisted of the null-terminating character.
1003 The number of parameters passed on a function call either exceeded the maximum number allowed, or was less than the minimum number required by the function.
1005 A parameter passed on a function call, required to be a string variable, was of a different variable type.
1006 A literal string was passed on a function call for a parameter which was required to be an output parameter.
4000 A parameter contains an invalid whole number value.
4001 A parameter contains an invalid number value.
4002 The result of an arithmetic operation had an exponent that was outside the supported range of -999,999,999 to +999,999,999.

Examples

Example 1:

@DTW_ADD(NUM1, NUM2, "2", result)

Example 2:

@DTW_rADD("12", NUM2, "5")

DTW_DIVIDE


AIX HP-UX Linux OS/2 OS/390 OS/400 SCO SUN Win NT
X X X X X X X X X

Purpose

Divides one number by the other.

Format

@DTW_DIVIDE(number1, number2, precision, result)

@DTW_DIVIDE(number1, number2, result)

@DTW_rDIVIDE(number1, number2, precision)

@DTW_rDIVIDE(number1, number2)

Parameters

Table 59. DTW_DIVIDE Parameters

Data Type Parameter Use Description
float number1 IN A variable or literal string representing a number that is to be divided.
float number2 IN A variable or literal string representing a number.
integer precision IN A variable or literal string representing a positive whole number that specifies the precision of the result. The default is 9.
float result OUT A variable that contains the result of number1 divided by number2.

Return Codes

Table 60. DTW_DIVIDE Return Codes

Return Code Explanation
-1001 The server could not process a Net.Data request to allocate memory.
1001 An input parameter contained a NULL value.
1002 An input parameter contained a string value which consisted of the null-terminating character.
1003 The number of parameters passed on a function call either exceeded the maximum number allowed, or was less than the minimum number required by the function.
1005 A parameter passed on a function call, required to be a string variable, was of a different variable type.
1006 A literal string was passed on a function call for a parameter which was required to be an output parameter.
4000 A parameter contains an invalid whole number value.
4001 A parameter contains an invalid number value.
4002 The result of an arithmetic operation had an exponent that was outside the supported range of -999,999,999 to +999,999,999.

Examples

Example 1:

@DTW_DIVIDE("8.0", NUM2, result)

Example 2:

@DTW_rDIVIDE("1", NUM2, "5")

Example 3:

@DTW_rDIVIDE(NUM1, "2", "5")

DTW_DIVREM


AIX HP-UX Linux OS/2 OS/390 OS/400 SCO SUN Win NT
X X X X X X X X X

Purpose

Divides one number by the other and returns the remainder.

Format

@DTW_DIVREM(number1, number2, precision, result)

@DTW_DIVREM(number1, number2, result)

@DTW_rDIVREM(number1, number2, precision)

@DTW_rDIVREM(number1, number2)

Parameters

Table 61. DTW_DIVREM Parameters

Data Type Parameter Use Description
float number1 IN A variable or literal string representing a number that is to be divided.
float number2 IN A variable or literal string representing a number.
integer precision IN A variable or literal string representing a positive whole number that specifies the precision of the result. The default is 9.
float result OUT A variable that contains the remainder of number1 divided by number2.

Return Codes

Table 62. DTW_DIVIDEREM Return Codes

Return Code Explanation
-1001 The server could not process a Net.Data request to allocate memory.
1001 An input parameter contained a NULL value.
1002 An input parameter contained a string value which consisted of the null-terminating character.
1003 The number of parameters passed on a function call either exceeded the maximum number allowed, or was less than the minimum number required by the function.
1005 A parameter passed on a function call, required to be a string variable, was of a different variable type.
1006 A literal string was passed on a function call for a parameter which was required to be an output parameter.
4000 A parameter contains an invalid whole number value.
4001 A parameter contains an invalid number value.
4002 The result of an arithmetic operation had an exponent that was outside the supported range of -999,999,999 to +999,999,999.

Usage Notes

The sign of the remainder, if nonzero, is the same as that of the first parameter.

Examples

Example 1:

@DTW_DIVREM(NUM1, NUM2, result)

Example 2:

@DTW_rDIVREM("10", NUM2)

Example 3:

@DTW_rDIVREM("3.6", "1.3")

Example 4:

@DTW_rDIVREM("-10", "3")

DTW_FORMAT


AIX HP-UX Linux OS/2 OS/390 OS/400 SCO SUN Win NT
X X X X X X X X X

Purpose

Customizes the formatting for a number.

Format

@DTW_FORMAT(number, before, after, expp, expt, precision, result)

@DTW_FORMAT(number, before, after, expp, expt, result)

@DTW_FORMAT(number, before, after, expp, result)

@DTW_FORMAT(number, before, after, result)

@DTW_FORMAT(number, before, result)

@DTW_FORMAT(number, result)

@DTW_rFORMAT(number, before, after, expp, expt, precision)

@DTW_rFORMAT(number, before, after, expp, expt)

@DTW_rFORMAT(number, before, after, expp)

@DTW_rFORMAT(number, before, after)

@DTW_rFORMAT(number, before)

@DTW_rFORMAT(number)

Parameters

Table 63. DTW_FORMAT Parameters

Data Type Parameter Use Description
float number IN A variable or literal string representing a number.
integer before IN A variable or literal string representing a positive whole number. This is an optional parameter. You must enter a null string ("") to have additional parameters.
integer after IN A variable or literal string representing a positive whole number. This is an optional parameter. You must enter a null string ("") to specify additional parameters.
integer expp IN A variable or literal string representing a positive whole number. You must specify a null string ("") to specify additional parameters.
integer expt IN A variable or literal string representing a positive whole number. You must enter a null string ("") to specify additional parameters.
integer precision IN A variable or literal string representing a positive whole number that specifies the precision of the result. The default is 9.
float result OUT A variable that contains the number with the specified rounding and formatting.

Return Codes

Table 64. DTW_FORMAT Return Codes

Return Code Explanation
-1001 The server could not process a Net.Data request to allocate memory.
1001 An input parameter contained a NULL value.
1002 An input parameter contained a string value which consisted of the null-terminating character.
1003 The number of parameters passed on a function call either exceeded the maximum number allowed, or was less than the minimum number required by the function.
1005 A parameter passed on a function call, required to be a string variable, was of a different variable type.
1006 A literal string was passed on a function call for a parameter which was required to be an output parameter.
4000 A parameter contains an invalid whole number value.
4001 A parameter contains an invalid number value.

Usage Notes

  1. If number is the only parameter is specified, the result is formatted as if @DTW_rADD(number,"0") was executed.
  2. The before and after parameters describe how many characters are used for the integer and decimal parts of the result parameter, respectively. If you omit either or both of these parameters, the number of characters used for that part is as many as is needed.
  3. If the before parameter is not large enough to contain the integer part of the number (plus the sign for a negative number), an error results. If the before parameter is larger than needed for that part, the number parameter value is padded on the left with blanks. If the after parameter is not the same size as the decimal part of the number parameter, the number is rounded (or extended with zeros) to fit. Specifying 0 causes the number to be rounded to an integer.
  4. The expp and expt parameters control the exponent part of the result. The expp parameter sets the number of places for the exponent part; the default is to use as many as is needed (which may be zero). The expt parameter sets the trigger point for use of exponential notation. The default is the default value of the precision parameter.
  5. If expp is 0, no exponent is supplied and the number is expressed in simple form with added zeros as necessary. If expp is not large enough to contain the exponent, an error results.
  6. If the number of places needed for the integer or decimal part exceeds expt or twice expt, respectively, use the exponential notation. If expt is 0, exponential notation is always used unless the exponent is 0. (If expp is 0, this overrides a 0 value of expt.) If the exponent is 0 when a nonzero expp is specified, then expp+2 blanks are supplied for the exponent part of the result. If the exponent is 0 and expp is not specified, the simple form is used.

Examples

Example 1:

@DTW_FORMAT(NUM, BEFORE, result)

Example 2:

@DTW_FORMAT("1.73", "4", "0", result)

Example 3:

@DTW_FORMAT("1.73", "4", "3", result)

Example 4:

@DTW_FORMAT(" - 12.73", "", "4", result)

Example 5:

@DTW_FORMAT("12345.73", "", "", "2", "2", result)

Example 6:

@DTW_FORMAT("1.234573", "", "3", "", "0", result)

Example 7:

@DTW_rFORMAT(" - 12.73")

Example 8:

@DTW_rFORMAT("0.000")

Example 9:

@DTW_rFORMAT("12345.73", "", "", "3", "6")

Example 10:

@DTW_rFORMAT("1234567e5", "", "3", "0")

Example 11:

@DTW_rFORMAT("12345.73", "", "3", "", "0")

DTW_INTDIV


AIX HP-UX Linux OS/2 OS/390 OS/400 SCO SUN Win NT
X X X X X X X X X

Purpose

Divides one number by the other and returns the integer part of the result.

Format

@DTW_INTDIV(number1, number2, precision, result)

@DTW_INTDIV(number1, number2, result)

@DTW_rINTDIV(number1, number2, precision)

@DTW_rINTDIV(number1, number2)

Parameters

Table 65. DTW_INTDIV Parameters

Data Type Parameter Use Description
float number1 IN A variable or literal string representing a number a number that is to be divided.
float number2 IN A variable or literal string representing a number.
integer precision IN A variable or literal string representing a positive whole number that specifies the precision of the result. The default is 9.
float result OUT A variable that contains integer part of number1 divided by number2.

Return Codes

Table 66. DTW_INTDIV Return Codes

Return Code Explanation
-1001 The server could not process a Net.Data request to allocate memory.
1001 An input parameter contained a NULL value.
1003 The number of parameters passed on a function call either exceeded the maximum number allowed, or was less than the minimum number required by the function.
1005 A parameter passed on a function call, required to be a string variable, was of a different variable type.
1006 A literal string was passed on a function call for a parameter which was required to be an output parameter.
4000 A parameter contains an invalid whole number value.
4001 A parameter contains an invalid number value.
4002 The result of an arithmetic operation had an exponent that was outside the supported range of -999,999,999 to +999,999,999.

Examples

Example 1:

@DTW_INTDIV(NUM1, NUM2, result)

Example 2:

@DTW_rINTDIV("2", NUM2)

DTW_MULTIPLY


AIX HP-UX Linux OS/2 OS/390 OS/400 SCO SUN Win NT
X X X X X X X X X

Purpose

Multiplies two numbers.

Format

@DTW_MULTIPLY(number1, number2, precision, result)

@DTW_MULTIPLY(number1, number2, result)

@DTW_rMULTIPLY(number1, number2, precision)

@DTW_rMULTIPLY(number1, number2)

Parameters

Table 67. DTW_MULTIPLY Parameters

Data Type Parameter Use Description
float number1 IN A variable or literal string representing a number.
float number2 IN A variable or literal string representing a number.
integer precision IN A variable or literal string representing a positive whole number that specifies the precision of the result. The default is 9.
float result OUT A variable that contains the product of number1 and number2.

Return Codes

Table 68. DTW_MULTIPLY Return Codes

Return Code Explanation
-1001 The server could not process a Net.Data request to allocate memory.
1001 An input parameter contained a NULL value.
1002 An input parameter contained a string value which consisted of the null-terminating character.
1003 The number of parameters passed on a function call either exceeded the maximum number allowed, or was less than the minimum number required by the function.
1005 A parameter passed on a function call, required to be a string variable, was of a different variable type.
1006 A literal string was passed on a function call for a parameter which was required to be an output parameter.
4000 A parameter contains an invalid whole number value.
4001 A parameter contains an invalid number value.
4002 The result of an arithmetic operation had an exponent that was outside the supported range of -999,999,999 to +999,999,999.

Examples

Example 1:

@DTW_MULTIPLY(NUM1, NUM2, result)

Example 2:

@DTW_rMULTIPLY("0.9", NUM2)

DTW_POWER


AIX HP-UX Linux OS/2 OS/390 OS/400 SCO SUN Win NT
X X X X X X X X X

Purpose

Raises a whole number to a whole number power.

Format

@DTW_POWER(number1, number2, precision, result)

@DTW_POWER(number1, number2, result)

@DTW_rPOWER(number1, number2, precision)

@DTW_rPOWER(number1, number2)

Parameters

Table 69. DTW_POWER Parameters

Data Type Parameter Use Description
float number1 IN A variable or literal string representing a number that is to be raised to a power.
float number2 IN A variable or literal string representing a number.
integer precision IN A variable or literal string representing a positive whole number that specifies the precision of the result. The default is 9.
float result OUT A variable that contains the result of number1 raised to the power of number2.

Return Codes

Table 70. DTW_POWER Return Codes

Return Code Explanation
-1001 The server could not process a Net.Data request to allocate memory.
1001 An input parameter contained a NULL value.
1003 The number of parameters passed on a function call either exceeded the maximum number allowed, or was less than the minimum number required by the function.
1005 A parameter passed on a function call, required to be a string variable, was of a different variable type.
1006 A literal string was passed on a function call for a parameter which was required to be an output parameter.
4000 A parameter contains an invalid whole number value.
4001 A parameter contains an invalid number value.
4002 The result of an arithmetic operation had an exponent that was outside the supported range of -999,999,999 to +999,999,999.

Examples

Example 1:

@DTW_POWER(NUM1, NUM2, result)

Example 2:

@DTW_rPOWER("1.7", NUM2, precision)

DTW_SUBTRACT


AIX HP-UX Linux OS/2 OS/390 OS/400 SCO SUN Win NT
X X X X X X X X X

Purpose

Subtracts one number from the other number.

Format

@DTW_SUBTRACT(number1, number2, precision, result)

@DTW_SUBTRACT(number1, number2, result)

@DTW_rSUBTRACT(number1, number2, precision)

@DTW_rSUBTRACT(number1, number2)

Parameters

Table 71. DTW_SUBTRACT Parameters

Data Type Parameter Use Description
float number1 IN A variable or literal string representing a number from which another number is to be subtracted.
float number2 IN A variable or literal string representing a number.
integer precision IN A variable or literal string representing a positive whole number that specifies the precision of the result. The default is 9.
float result OUT A variable that contains the difference of number1 and number2.

Return Codes

Table 72. DTW_SUBTRACT Return Codes

Return Code Explanation
-1001 The server could not process a Net.Data request to allocate memory.
1001 An input parameter contained a NULL value.
1002 An input parameter contained a string value which consisted of the null-terminating character.
1003 The number of parameters passed on a function call either exceeded the maximum number allowed, or was less than the minimum number required by the function.
1005 A parameter passed on a function call, required to be a string variable, was of a different variable type.
1006 A literal string was passed on a function call for a parameter which was required to be an output parameter.
4000 A parameter contains an invalid whole number value.
4001 A parameter contains an invalid number value.
4002 The result of an arithmetic operation had an exponent that was outside the supported range of -999,999,999 to +999,999,999.

Examples

Example 1:

@DTW_SUBTRACT(NUM1, NUM2, comp)
%IF(comp > "0")
<P>$(NUM1) is larger than  $(NUM2).
%ENDIF
 

This example shows a way to compare numeric values, which are strings in Net.Data.

Example 2:

@DTW_SUBTRACT(NUM1, NUM2, result)

Example 3:

@DTW_rSUBTRACT("1.3", NUM2)


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]