Arithmetic Expression Examples: BizTalk Services
Updated: August 31, 2015
Lists Arithmetic Expression examples in Microsoft Azure BizTalk Services.
All arithmetic input values are based on Numeric Literals to represent numerical values of the CLR System.Double type. The following examples demonstrate the supported numerical literals:

100

100.25

0.25

.25

8e2, 8e+2, 8E2, 8E+2

1.2e8

1.2e8, 1.2E8
Important 

The Transform parser does not support suffixes that indicate the data type of a numeric literal. For example, using 2L to be represented as Long is not supported. 
The Double.TryParse() method is used to verify that a numeric literal value is a valid double value. If it is not a valid double value, the argument is converted to a double using the Convert.ToDouble() method. If the conversion fails, the value is zero.
Arithmetic expression reminders:

If an arithmetic expression has more than one operator, then multiplication, division and modulo are evaluated first. Then, addition and subtraction are evaluated.

Use parenthesis to control the order. For example, adding or subtracting input values within parenthesis allows this part of the expression to be evaluated first.

Numeric Values are not rounded unless Round is specifically used.
The following sample expressions use the following input values:
Input1 
ab123.456 
Input2 
78.9 
Input3 
123.11 
Based off the Expression.Add method. Requires two arguments of the type double. If a conversion to double fails, the value is zero and the operation is performed.
Expression  Result 

Input1+Input2 
0 + 78.9 = 78.9 Input1 is 0 because the conversion to a double fails. 
Input1+Input2+Input3 
0 + 78.9 + (123.11) = 44.21 Input1 is 0 because the conversion to a double fails. 
Input2+Input3 
78.9 + (123.11) = 44.21 
Input1+Input3 
0 + (123.11) = 123.11 Input1 is 0 because the conversion to a double fails. 
Based off the Expression.Subtract method. Requires two arguments of the type double. If a conversion to double fails, the value is zero and the operation is performed.
Expression  Result 

Input1Input2 
0  78.9 = 78.9 Input1 is 0 because the conversion to a double fails. 
Input1Input2Input3 
0  78.9 – (123.11) = 44.21 Input1 is 0 because the conversion to a double fails. 
Input2Input3 
78.9  (123.11) = 44.21 
Input1Input3 
0 – (123.11) = 123.11 Input1 is 0 because the conversion to a double fails. 
(Input1+Input2)Input3 
(0 + 78.9) – (123.11) = 202.11 Input1 is 0 because the conversion to a double fails. 
Based off the Expression.Multiply method. Requires two arguments of the type double.
If a conversion to double fails, the value is zero and the operation is performed. If both inputs are successfully converted to double, then the multiplication occurs and the value is returned. If only one of the inputs is successfully converted to double, then the value of that input is returned. If none of the inputs are successfully converted to double, then zero is returned.
Expression  Result 

Input1*Input2 
0 * 78.9 = 78.9 Input1 is 0 because the conversion to a double fails. 
Input1*Input2*Input3 
0 * 78.9 * (123.11) = 9713.379 Input1 is 0 because the conversion to a double fails. 
Input2*Input3 
78.9 * (123.11) = 9713.379 
Input1*Input3 
0 * (123.11) = 123.11 Input1 is 0 because the conversion to a double fails. 
(Input1*Input2)Input3*Input2 
(0 * 78.9) – (123.11) * 78.9 = 78.9 – (9713.379) = 9792.279 Input1 is 0 because the conversion to a double fails. 
Based off the Expression.Divide method. Requires two arguments of the type double.
If a conversion to double fails, the value is zero and the operation is performed. If both inputs are successfully converted to double and the denominator value is nonzero, then the division occurs and the value is returned. Otherwise, zero is returned.
Expression  Result 

Input1/Input2 
0 / 78.9 = 0 Input1 is 0 because the conversion to a double fails. 
Input1/Input2/Input3 
0 / 78.9 / (123.11) = 0 Input1 is 0 because the conversion to a double fails. 
Input2/Input3 
78.9 / (123.11) = 0.6408902 
Input3/Input1 
123.11 / 0 = 0 Input1 is 0 because the conversion to a double fails. When the denominator is zero, the output will be zero. 
(Input1/Input2)Input2/Input3 
(0 / 78.9) – (123.11 / 78.9) = 0 – (1.560329531051965) = 1.560329531051965 Input1 is 0 because the conversion to a double fails. 
Based off the Expression.Modulo method. Requires two arguments of the type double.
If a conversion to double fails, the value is zero and the operation is performed. If both inputs are successfully converted to double and the denominator value is nonzero, then the remainder is returned. Otherwise, zero is returned.
Expression  Result 

Input1%2 
0 % 2 = 0 Input1 is 0 because the conversion to a double fails. 
Input1+Input2%4 
0 + 78.9 % 4 = 2.9 Input1 is 0 because the conversion to a double fails. 78.9 / 4 = 19.725; 19 is the quotient and 2.9 is the remainder because 78.9 = 4 * 19 + 2.9 
Input2%Input1 
78.9 % 0 = 0 Input1 is 0 because the conversion to a double fails. 
Input3%Input2 
123.11 % 78.9 = 44.21 123.11 / 78.9 = 1.560329531051965; 1 is the quotient and 44.21 is the remainder because 123.11 = 78.9 * (1) + (44.21) 
(Input1%Input2)*Input2%Input3 
(0 % 78.9) * (78.9 % (123.11)) = 0 * (78.9) = 0 Input1 is 0 because the conversion to a double fails. 78.9 / 123.11 = 0.6408902607424255; 0 is the quotient and 78.9 is the remainder because 78.9 = 123.11 * (0) + 78.9 
Based off the Math.Abs method. Requires a single argument and converts it to double. If the conversion to double is successful, it returns the absolute value of the argument. Otherwise, zero is returned.
Expression  Result 

Abs(Input1) 
0 Input1 is 0 because the conversion to a double fails. 
Abs(Input2) 
78.9 
Abs(Input3) 
123.11 
Abs(Input1)+Abs(Input2)+Abs(Input3) 
0 + 78.9 + 123.11 = 202.01 
(Abs(Input1)*Abs(Input2))*Input2%Abs(Input3) 
(0*78.9) * 78.9 % 123.11 = 78.9 * 78.9 % 123.11 = 6225.21 % 123.11 = 69.71 Input1 is 0 because the conversion to a double fails. (0*78.9): Remember with multiplication, if only one of the arguments can be successfully converted to double, then the value of that argument is returned. 6225.21 / 123.11 = 50.566241; 50 is the quotient and 69.71 is the remainder because 6225.21 = 123.11 * 50 + 69.71 
Based off the Math.Max method. Requires two arguments of the type double.
If both inputs are successfully converted to double, then the maximum value of the two input values is returned. If only one of the inputs is successfully converted to double, then the value of that input is returned. If none of the inputs are successfully converted to double, then zero is returned.
Expression  Result 

Max(Input1, Input2) 
78.9 Input1 fails the conversion to double so the second input value is returned. 
Max(Input2, Input3) 
78.9 
Max(Input3, Input2)+Max(Input2, Input1)+Max(Input3, Input1) 
78.9 + 78.9 + (123.11) = 34.69 Input1 fails the conversion to double so the second input value is returned. 
(Max(Input1, Input3)*Max(Input2, Input3))* Input2%Abs(Max(Input3, Input1)) 
((123.11) * 78.9) * 78.9 % 123.11 = 9713.379 * 78.9 % 123.11 = 766385.6031 % 123.11 = 25.8531 Input1 fails the conversion to double so the second input value is returned. 766385.6031 / 123.11 = 6225.21; 6225 is the quotient and 25.8531 is the remainder because 766385.6031 = 123.11 * (6225) + (25.8531) 
Based off the Math.Min method. Requires two arguments of the type double.
If both inputs are successfully converted to double, then the minimum value of the two input values is returned. If only one of the inputs is successfully converted to double, then the value of that input is returned. If none of the inputs are successfully converted to double, then zero is returned.
Expression  Result 

Min(Input1, Input2) 
78.9 Input1 fails the conversion to double so the second input value is returned. 
Min(Input2, Input3) 
123.11 
Min(Input3, Input2)+ Min(Input2, Input1)+Min(Input3, Input1) 
(123.11) + 78.9 + (123.11) = 167.32 Input1 fails the conversion to double so the second input value is returned. 
(Min(Input1, Input3)*Min(Input2, Input3))*Input2%Abs(Min(Input3, Input1)) 
((123.11) * (123.11)) * 78.9 % 123.11 = 15156.0721 * 78.9 % 123.11 = 1195814.08869 % 123.11 = 46.65869 Input1 fails the conversion to double so the second input value is returned. 1195814.08869 / 123.11 = 9713.379; 9713 is the quotient and 46.65869 is the remainder because 1195814.08869 = 123.11 * 9713 + 46.65869 
Based off the Math.Round method. Requires at least one argument that is converted to double and an optional second argument that must be a nonnegative integer. If the conversion fails, zero is returned.
If the second argument is not provided, then the first argument is rounded to the nearest integer. If the second argument is a positive integer, then the first argument is rounded to number of digits specified in the second argument. The maximum number of digits to round is 15. Higher values for the second argument will still result in rounding to 15 places. If the second argument cannot be converted to a nonnegative integer, zero is returned.
Expression  Result 

Round(Input1) 
0 Input1 is 0 because the conversion to a double fails. 
Round(Input3, 1) 
123.1 
Round(Input3, 5) 
123.11 
Round(Input2)*Round(Input3, 1) 
79 * (123.1) = 9724.9 
Round(Input3)/Round(Input2, 17)*Round(Input3) 
123 / 78.9 * 123 = 1.5589353 * 123 = 191.74904 
Based off the Math.Sqrt method. Requires a single argument and converts it to double. If the conversion is successful, the square root is returned. If the argument is a negative number, NaN is returned. If the conversion fails, zero is returned.
Expression  Result 

Sqrt(Input1) 
0 Input1 is 0 because the conversion to a double fails. 
Sqrt(Input2) 
8.882567196480981 
Sqrt(Input3, 5) 
NaN Input3 is NaN (Not a Number) because the input is negative. 
Sqrt(Input1)+Sqrt(Input2)*Sqrt(Input3) 
0 + 8.882567196480981 * NaN = NaN Input1 is 0 because the conversion to a double fails. Input3 is NaN because the string is a negative number. Any arithmetic operation that involves NaN will result in NaN. 
Sqrt(Input2)+Round(Input3, 1)*Abs(Input1) 
8.882567196480981 + (123.1) * 0 = 8.882567196480981 + (123.1) = 114.217432803519 Input1 is 0 because the conversion to a double fails. (123.1 * 0): Remember with multiplication, if only one of the arguments can be successfully converted to double, then the value of that argument is returned. 
If an error occurs with an Arithmetic Expression Map Operation, by default, the entire Transform is aborted. This error handling behavior is configurable. See Error and Data Handling at Expressions in BizTalk Services  Usage and Examples.
See Also