Math services
Use Math services to perform mathematical operations on string-based numeric values. Services that operate on integer values use Java™'s long data type (64-bit, two's complement). Services that operate on float values use Java's double data type (64-bit IEEE 754). If extremely precise calculations are critical to your application, you should write your own Java services to perform math functions.
absoluteValue
Returns the absolute value of the input number.
Input parameters for absoluteValue
- num: String - Number whose absolute value is to be returned.
Output parameters for absoluteValue
- positiveNumber: String - Absolute value of the input number.
addFloatList
Adds a list of floating point numbers (represented in a string list) and returns the sum.
Input parameters for addFloatList
- numList: String List - Numbers (floating point numbers represented in a string list) to add.
Output parameters for addFloatList
-
value: String - Sum of the numbers in numList. If a sum cannot be produced, value contains one of the following:
Infinity- The computation produces a positive value that overflows the representable range of a float type.-Infinity- The computation produces a negative value that overflows the representable range of a float type.0.0- The computation produces a value that underflows the representable range of a float type (for example, adding a number to infinity).NaN- The computation produces a value that cannot be represented as a number (for example, any operation that uses NaN as input, such as 10.0 + NaN = NaN).
Usage notes for addFloatList
Make sure the strings that are passed to the service in numList are in a locale-neutral format
(that is, using the pattern -####.##). Passing locally formatted strings may result
in unexpected results. For example, calling addFloats in a German locale with the arguments
1,23 and 2,34 will result in the value 357, not
3.57 or 3,57.
addFloats
Adds one floating point number (represented as a String) to another and returns the sum.
Input parameters for addFloats
-
num1: String - Number to add.
-
num2: String - Number to add.
-
precision: String Optional - Number of decimal places to which the sum will be rounded. The default value is null.
Output parameters for addFloats
-
value: String - Sum of the numbers in num1 and num2. If a sum cannot be produced, value contains one of the following:
-
Infinity- The computation produces a positive value that overflows the representable range of a float type. -
-Infinity- The computation produces a negative value that overflows the representable range of a float type. -
0.0- The computation produces a value that underflows the representable range of a float type (for example, adding a number to infinity). -
NaN- The computation produces a value that cannot be represented as a number (for example, any operation that uses NaN as input, such as 10.0 + NaN = NaN).
-
Usage notes for addFloats
Make sure the strings that are passed to the service in num1andnum2 are in a locale-neutral
format (that is, using the pattern -####.##). Passing locally formatted strings may
result in unexpected results. For example, calling addFloats in a German locale with the arguments
1,23 and 2,34 will result in the value 357, not
3.57 or 3,57.
addIntList
Adds a list of integers (represented in a String list) and returns the sum.
Input parameters for addIntList
- numList: String List - Numbers (integers represented as Strings) to add.
Output parameters for addIntList
- value: String - Sum of the numbers in numList.
Usage notes for addIntList
Make sure the strings that are passed to the service in numList are in a locale-neutral format
(that is, using the pattern -####.##). Passing locally formatted strings may result
in unexpected results. For example, calling addFloats in a German locale with the arguments
1,23 and 2,34 will result in the value 357, not
3.57 or 3,57.
addInts
Adds one integer (represented as a String) to another and returns the sum.
Input parameters for addInts
Adds one integer (represented as a String) to another and returns the sum.
-
num1: String - Number (integer represented as a String) to add.
-
num2: String - Number (integer represented as a String) to add.
Output parameters for addInts
- value: String - Sum of num1 and num2.
Usage notes for addInts
Ensure that the result of your calculation is less than 64 bits in width (the maximum width for the long data type). If the result exceeds this limit, it will generate a data overflow.
Ensure that the strings that are passed to the service in num1andnum2 are in a locale-neutral
format (that is, using the pattern -####.##). Passing locally formatted strings may
result in unexpected results. For example, calling addFloats in a German locale with the arguments
1,23 and 2,34 will result in the value 357, not
3.57 or 3,57.
addObjects
Adds one java.lang.Number object to another and returns the sum.
Input parameters for addObjects
-
num1: java.lang.Number - Number to add. See the Usage Notes for supported sub-classes.
-
num2: java.lang.Number - Number to add. See the Usage Notes for supported sub-classes.
Output parameters for addObjects
- value: java.lang.Number - Sum of the numeric values of num1 and num2.
Usage notes for addObjects
This service accepts the following sub-classes of java.lang.Number: java.lang.Byte, java.lang.Double, java.lang.Float, java.lang.Integer, java.lang.Long, java.lang.Short.
This service applies the following rules for binary numeric promotion to the operands in order:
- If either operand is of type Double, the other is converted to Double.
- Otherwise, if either operand is of type Float, the other is converted to Float.
- Otherwise, if either operand is of type Long, the other is converted to Long.
- Otherwise, both operands are converted to type Integer.
These promotion rules mirror the Java rules for numeric promotion of numeric types.
divideFloats
Divides one floating point number (represented as a String) by another (num1/num2) and returns the quotient.
Input parameters for divideFloats
-
num1: String - Number (floating point number represented as a String) that is the dividend.
-
num2: String - Number (floating point number represented as a String) that is the divisor.
-
precision: String Optional - Number of decimal places to which the quotient will be rounded. The default value is null.
Output parameters for divideFloats
-
value: String - The quotient of num1 / num2. If a quotient cannot be produced, value contains one of the following:
-
Infinity- The computation produces a positive value that overflows the representable range of a float type. -
-Infinity- The computation produces a negative value that overflows the representable range of a float type. -
0.0- The computation produces a value that underflows the representable range of a float type (for example, dividing a number by infinity). -
NaN- The computation produces a value that cannot be represented as a number (for example, the result of an illegal operation such as dividing zero by zero or any operation that uses NaN as input, such as 10.0 + NaN = NaN).
-
Usage notes for divideFloats
Make sure the strings that are passed to the service in num1andnum2 are in a locale-neutral
format (that is, using the pattern -####.##). Passing locally formatted strings may
result in unexpected results. For example, calling addFloats in a German locale with the arguments
1,23 and 2,34 will result in the value 357, not
3.57 or 3,57.
divideInts
Divides one integer (represented as a String) by another (num1/num2) and returns the quotient.
Input parameters for divideInts
-
num1: String - Number (integer represented as a String) that is the dividend.
-
num2: String - Number (integer represented as a String) that is the divisor.
Output parameters for divideInts
- value: String - The quotient of num1 / num2.
Usage notes for divideInts
Make sure the strings that are passed to the service in num1andnum2 are in a locale-neutral
format (that is, using the pattern -####.##). Passing locally formatted strings may
result in unexpected results. For example, calling addFloats in a German locale with the arguments
1,23 and 2,34 will result in the value 357, not
3.57 or 3,57.
divideObjects
Divides one java.lang.Number object by another (num1/num2) and returns the quotient.
Input parameters for divideObjects
-
num1: java.lang.Number - Number that is the dividend. See the Usage Notes for supported sub-classes.
-
num2: java.lang.Number - Number that is the divisor. See the Usage Notes for supported sub-classes.
Output parameters for divideObjects
- value: java.lang.Number - Quotient of num1 / num2.
Usage notes for divideObjects
This service accepts the following sub-classes of java.lang.Number: java.lang.Byte, java.lang.Double, java.lang.Float, java.lang.Integer, java.lang.Long, java.lang.Short.
This service applies the following rules for binary numeric promotion to the operands in order:
- If either operand is of type Double, the other is converted to Double.
- Otherwise, if either operand is of type Float, the other is converted to Float.
- Otherwise, if either operand is of type Long, the other is converted to Long.
- Otherwise, both operands are converted to type Integer.
These promotion rules mirror the Java rules for numeric promotion of numeric types.
max
Returns the maximum numeric value from a list of numbers.
Input parameters for max
- numList: String List - List of numbers from which the maximum value is to be returned.
Output parameters for max
- maxValue: String - Maximum numeric value from the list of numbers.
min
Returns the minimum numeric number from a list of numbers.
Input parameters for min
- numList: String List - List of numbers from which the minimum value is to be returned.
Output parameters for min
- minValue: String - Minimum numeric value from the list of numbers.
multiplyFloatList
Multiplies a list of floating point numbers (represented in a String list) and returns the product.
Input parameters for multiplyFloatList
- numList: String List - Numbers (floating point numbers represented as Strings) to multiply.
Output parameters for multiplyFloatList
-
value: String - Product of the numbers in numlist. If a product cannot be produced, value contains one of the following:
-
Infinity: The computation produces a positive value that overflows the representable range of a float type. -
-Infinity: The computation produces a negative value that overflows the representable range of a float type. -
0.0- The computation produces a value that underflows the representable range of a float type (for example, multiplying a number by infinity). -
NaN- The computation produces a value that cannot be represented as a number (for example, the result of an illegal operation such as multiplying zero by zero or any operation that uses NaN as input, such as 10.0 + NaN = NaN).
-
Usage notes for multiplyFloatList
Make sure the strings that are passed to the service in numList are in a locale-neutral format
(that is, using the pattern -####.##). Passing locally formatted strings may result
in unexpected results. For example, calling addFloats in a German locale with the arguments
1,23 and 2,34 will result in the value 357, not
3.57 or 3,57.
multiplyFloats
Multiples one floating point number (represented as String) by another and returns the product.
Input parameters for multiplyFloats
-
num1: String - Number (floating point number represented as a String) to multiply.
-
num2: String - Number (floating point number represented as a String) to multiply.
-
precision: String Optional - Number of decimal places to which the product will be rounded. The default value is null.
Output parameters for multiplyFloats
-
value: String - Product of the numeric values of num1 and num2. If a product cannot be produced, value contains one of the following:
-
Infinity- The computation produces a positive value that overflows the representable range of a float type. -
-Infinity|The computation produces a negative value that overflows the representable range of a float type. -
0.0|The computation produces a value that underflows the representable range of a float type (for example, multiplying a number by infinity). -
NaN|The computation produces a value that cannot be represented as a number (for example, the result of an illegal operation such as multiplying zero by zero or any operation that uses NaN as input, such as 10.0 + NaN = NaN).
-
Usage notes for multiplyFloats
Make sure the strings that are passed to the service in num1andnum2 are in a
locale-neutral format (that is, using the pattern -####.##).
Passing locally formatted strings may result in unexpected results. For example,
calling addFloats in a German locale with the arguments 1,23
and 2,34 will result in the value 357, not
3.57 or 3,57.
multiplyIntList
Multiplies a list of integers (represented in a String list) and returns the product.
Input parameters for multiplyIntList
- numList: String List - Numbers (floating point numbers represented as Strings) to multiply.
Output parameters for multiplyIntList
- value: String - Product of the numbers in numList.
Usage notes for multiplyIntList
Make sure the result of your calculation is less than 64 bits in width (the maximum width for the long data type). If the result exceeds this limit, it will generate a data overflow.
Make sure the strings that are passed to the service in numList are in a locale-neutral format
(that is, using the pattern -####.##). Passing locally formatted strings may result
in unexpected results. For example, calling addFloats in a German locale with the arguments
1,23 and 2,34 will result in the value 357, not
3.57 or 3,57.
multiplyInts
Multiplies one integer (represented as a String) by another and returns the product.
Input parameters for multiplyInts
- num1: String - Number (integer represented as a String) to multiply.
- num2: String - Number (integer represented as a String) to multiply.
Output parameters for multiplyInts
- value: String - Product of num1 and num2.
Usage notes for multiplyInts
Make sure the result of your calculation is less than 64 bits in width (the maximum width for the long data type). If the result exceeds this limit, it will generate a data overflow.
Make sure the strings that are passed to the service in num1andnum2 are in a locale-neutral
format (that is, using the pattern -####.##). Passing locally formatted strings may
result in unexpected results. For example, calling addFloats in a German locale with the arguments
1,23 and 2,34 will result in the value 357, not
3.57 or 3,57.
multiplyObjects
Multiplies one java.lang.Number object by another and returns the product.
Input parameters for multiplyObjects
- num1: java.lang.Number - Number to multiply. See the Usage Notes for supported sub-classes.
- num2: java.lang.Number - Number to multiply. See the Usage Notes for supported sub-classes.
Output parameters for multiplyObjects
- value: java.lang.Number - Product of num1 and num2.
Usage notes for multiplyObjects
This service accepts the following sub-classes of java.lang.Number: java.lang.Byte, java.lang.Double, java.lang.Float, java.lang.Integer, java.lang.Long, java.lang.Short.
This service applies the following rules for binary numeric promotion to the operands in order:
- If either operand is of type Double, the other is converted to Double.
- Otherwise, if either operand is of type Float, the other is converted to Float.
- Otherwise, if either operand is of type Long, the other is converted to Long.
- Otherwise, both operands are converted to type Integer.
These promotion rules mirror the Java rules for numeric promotion of numeric types.
randomDouble
Returns the next pseudorandom, uniformly distributed double between 0.0 and 1.0. Random number generators are often referred to as pseudorandom number generators because the numbers produced tend to repeat themselves over time.
Input parameters for randomDouble
- fractionLength: String - Specifies the number of digits for the generated random number. For example, if you specify 7, the random number generated will be 0.6536596.
Output parameters for randomDouble
- number: String - Generated random number.
roundNumber
Returns a rounded number.
Input parameters for roundNumber
- num: String - Number to be rounded.
- numberOfDigits: String - Specifies the number of digits to which you want to round the number.
- roundingMode: String Optional - Specifies the rounding method. Valid values for the
roundingMode parameter are
RoundHalfUp,RoundUp,RoundDown,RoundCeiling,RoundFloor,RoundHalfDown, andRoundHalfEven. The default value isRoundHalfUp.
Output parameters for roundNumber
- roundedNumber: String - The rounded number.
subtractFloats
Subtracts one floating point number (represented as a String) from another and returns the difference.
Input parameters for subtractFloats
- num1: String - Number (floating point number represented as a String).
- num2: String - Number (floating point number represented as a String) to subtract from num1.
- precision: String Optional - Number of decimal places to which the difference will be rounded. The default value is null.
Output parameters for subtractFloats
- value: String - Difference of num1 - num2. If a difference cannot be produced, value contains one of the following:
Infinity- The computation produces a positive value that overflows the representable range of a float type.-Infinity- The computation produces a negative value that overflows the representable range of a float type.0.0- The computation produces a value that underflows the representable range of a float type (for example, subtracting a number from infinity).NaN- The computation produces a value that cannot be represented as a number (for example, the result of an illegal operation such as multiplying zero by zero or any operation that uses NaN as input, such as 10.0 - NaN = NaN).
Usage notes for subtractFloats
Make sure the strings that are passed to the service in num1andnum2 are in a locale-neutral
format (that is, using the pattern -####.##). Passing locally formatted strings may
result in unexpected results. For example, calling addFloats in a German locale with the arguments
1,23 and 2,34 will result in the value 357, not
3.57 or 3,57.
subtractInts
Subtracts one integer (represented as a String) from another and returns the difference.
Input parameters for subtractInts
- num1: String - Number (integer represented as a String).
- num2: String - Number (integer represented as a String) to subtract from num1.
Output parameters for subtractInts
- value: String - Difference of num1 - num2.
Usage notes for subtractInts
Make sure the result of your calculation is less than 64 bits in width (the maximum width for the long data type). If the result exceeds this limit, it will generate a data overflow.
Make sure the strings that are passed to the service in num1 andnum2 are in a locale-neutral
format (that is, using the pattern -####.##). Passing locally formatted strings may
result in unexpected results. For example, calling addFloats in a German locale with the arguments
1,23 and 2,34 will result in the value 357, not
3.57 or 3,57.
subtractObjects
Subtracts one java.lang.Number object from another and returns the difference.
Input parameters for subtractObjects
- num1: java.lang.Number - Number. See the Usage Notes for supported sub-classes.
- num2: java.lang.Number - Number to subtract from num1. See the Usage Notes for supported sub-classes.
Output parameters for subtractObjects
- value: java.lang.Number - Difference of num1 - num2.
Usage notes for subtractObjects
This service accepts the following sub-classes of java.lang.Number: java.lang.Byte, java.lang.Double, java.lang.Float, java.lang.Integer, java.lang.Long, java.lang.Short.
This service applies the following rules for binary numeric promotion to the operands. The following rules are applied in order:
- If either operand is of type Double, the other is converted to Double.
- Otherwise, if either operand is of type Float, the other is converted to Float.
- Otherwise, if either operand is of type Long, the other is converted to Long.
- Otherwise, both operands are converted to type Integer.
These promotion rules mirror the Java rules for numeric promotion of numeric types.
toNumber
Converts a string to numeric data type.
Input parameters for toNumber
- num: String - Number (represented as a string) to be converted to numeric format.
- convertAs: String Optional - Specifies the Java numeric data type to which the num parameter is to be converted. Valid values for the
convertAs parameter are
java.lang.Double,java.lang.Float,java.lang.Integer,java.math.BigDecimal,java.math.BigInteger,java.lang.Long. The default value isjava.lang.Double.
Output parameters for toNumber
- num: java.lang.Number - Converted numeric object.