All product information in wiki.bizagi.com is only valid for Bizagi BPM Suite 9.1.X.
For newer Bizagi BPM Suite versions (10.X and up) please visit the User Guide.
 

Using Mathematical Functions in Rules

From Business Process Management, BPM and Workflow Automation Wiki | BizAgi BPMS

Jump to: navigation, search

<keywords content="keywords"> math, System.Math, Abs, Ceiling, Floor, Max, Min, Pow, Round, Sqrt, exponential, square root, absolute value, power </keywords>

Using Mathematical Functions in Rules

A Bizagi project may require special operations over numbers, such as finding out its absolute value or square root or rounding a number. This can be accomplished using the methods from the Math class of .NET Framework. In a rule the method is used like this:

System.Math.[method_name].

For methods of the class that are overloaded, a cast of the parameters must be done depending on which overload is going to be used.

Care must be taken to select the correct type with operations using business data.  For example, it is incorrect to create an attribute of Integer type if a number such as 170.62 needs to be saved in it.


  • In this example, the third power of a business value is obtained and then saved in another business value.


If <VacationRequest.BaseNumber> = 2 then <VacationRequest.ResultNumber> is assigned with 8.


  • In this other example, a business value with decimal fraction is rounded to an integer.

If <VacationRequest.BaseNumber> = 14.667 then <VacationRequest.ResultNumber> is assigned with 15.

Some Useful Math Methods

(Taken from .NET documentation)
NaN: Not a number

Method Description Use in Bizagi (using only two overloaded methods) Return Value Example
Abs Returns the absolute value of a specified number. System.Math.Abs((decimal)(value));
System.Math.Abs((int)(value));
A double-precision floating-point number, x, such that 0 ≤ x ≤ MaxValue. System.Math.Abs(-4.79) = 4.79
System.Math.Abs(32) = 32
Ceiling Returns the smallest whole number greater than or equal to the specified number. System.Math.Ceiling(num); The smallest whole number greater than or equal to num. System.Math.Ceiling(0.00) = 0
System.Math.Ceiling(0.90) = 1
System.Math.Ceiling(1.00) = 1
System.Math.Ceiling(1.10) = 2
Floor Returns the largest whole number less than or equal to the specified number. System.Math.Floor(num); The largest whole number less than or equal to num. System.Math.Floor(2.10) = 2
System.Math.Floor(2.00) = 2
System.Math.Floor(1.90) = 1
Max Returns the larger of two specified numbers. System.Math.Max((decimal)(val1), (decimal)(val2));
System.Math.Max((double)(val1), (double)(val2));
Parameter val1 or val2, whichever is larger. If val1, val2, or both val1 and val2 are equal to NaN, NaN is returned. System.Math.Max(6, 56) = 56
Min Returns the smaller of two numbers. System.Math.Min((int)(val1), (int)(val2));
System.Math.Min((long)(val1), (long)(val2));
Parameter val1 or val2, whichever is smaller. If val1, val2, or both val1 and val2 are equal to NaN, NaN is returned. System.Math.Min(-4, 54) = -4
Pow Returns a specified number raised to the specified power. System.Math.Pow(x, y); The number x raised to the power y. System.Math.Pow(100, 2) = 10000
Round Returns the number nearest the specified value. System.Math.Round((decimal)(value));
System.Math.Round((double)(value), (int)(digits));
The number nearest value with precision equal to digits. If value is halfway between two numbers, one of which is even and the other odd, then the even number is returned. If the precision of value is less than digits, then value is returned unchanged. System.Math.Round(3.48) = 3
System.Math.Round(3.44, 1) = 3.4
System.Math.Round(3.45, 1) = 3.4
System.Math.Round(3.46, 1) = 3.5
Sqrt Returns the square root of a specified number. System.Math.Sqrt(num); If num is zero or positive, the positive square. If num is negative, NaN. System.Math.Sqrt(144) = 12

<comments />