Math functions are available throughout the Articles report script editor. They provide tools for arithmetic, rounding, trigonometry, and safe numeric operations within your report scripts and expressions.
Abs
Returns the absolute (non-negative) value of a number.
Abs(E: Extended): Extended
| Parameter | Type | Description |
|---|---|---|
| E | Extended | The number to evaluate |
// Show a variance without a negative sign
Result := FormatCurrencySafe(Abs([Budget.Variance]));
// Check if a value is within a tolerance regardless of direction
if Abs([Sensor.Reading] - [Sensor.Target]) < 0.5 then
Result := 'Within tolerance'
else
Result := 'Out of range';
ArcTan
Returns the arctangent of a number in radians.
ArcTan(X: Extended): Extended
| Parameter | Type | Description |
|---|---|---|
| X | Extended | The value to evaluate |
// Calculate Pi using ArcTan
var pi := ArcTan(1) * 4;
Result := FloatToStr(pi);
// Returns: '3.14159265358979'
Clamp
Restricts a value to within a specified minimum and maximum range. If the value is below the minimum, the minimum is returned. If above the maximum, the maximum is returned. Otherwise the value itself is returned.
Clamp(Value, Min, Max: Double): Double
| Parameter | Type | Description |
|---|---|---|
| Value | Double | The value to clamp |
| Min | Double | The minimum allowed value |
| Max | Double | The maximum allowed value |
// Ensure a discount never goes below 0 or above 50%
Result := FormatNumberSafe(Clamp([Orders.DiscountRate], 0, 0.5), 2);
// Cap a commission rate between 1% and 15%
var rate := Clamp([Employee.CommissionRate], 0.01, 0.15);
Result := FormatFloat('0.00"%"', rate * 100);
// Keep a quantity within valid bounds
var qty := Clamp([Orders.Quantity], 1, 9999);
Cos
Returns the cosine of an angle given in radians.
Cos(E: Extended): Extended
| Parameter | Type | Description |
|---|---|---|
| E | Extended | Angle in radians |
var pi := ArcTan(1) * 4;
Result := FloatToStr(Cos(pi));
// Returns: '-1' (cosine of 180 degrees)
Exp
Returns e raised to the power of X (the natural exponential function).
Exp(X: Extended): Extended
| Parameter | Type | Description |
|---|---|---|
| X | Extended | The exponent |
// Compound growth calculation
var growth := Exp([Rate] * [Years]);
Result := FormatCurrencySafe([Principal] * growth);
Frac
Returns the fractional part of a floating point number (the part after the decimal point).
Frac(X: Extended): Extended
| Parameter | Type | Description |
|---|---|---|
| X | Extended | The number to evaluate |
Result := FloatToStr(Frac(12.75));
// Returns: '0.75'
// Extract cents from a dollar amount
var cents := Round(Frac([Invoice.Amount]) * 100);
Result := IntToStr(cents) + ' cents';
Int
Returns the integer part of a floating point number, discarding the decimal portion. Unlike Trunc, Int returns a float type rather than an integer type.
Int(E: Extended): Integer
| Parameter | Type | Description |
|---|---|---|
| E | Extended | The number to evaluate |
Result := FloatToStr(Int(12.75));
// Returns: '12'
// Extract the whole dollar amount
Result := 'Dollars: ' + FloatToStr(Int([Invoice.Amount]));
IsBetween
Returns True if a value falls within a specified range, inclusive of both the minimum and maximum bounds.
IsBetween(Value, Min, Max: Double): Boolean
| Parameter | Type | Description |
|---|---|---|
| Value | Double | The value to check |
| Min | Double | The lower bound (inclusive) |
| Max | Double | The upper bound (inclusive) |
// Classify an order by size
if IsBetween([Orders.Total], 0, 500) then
Result := 'Small'
else if IsBetween([Orders.Total], 501, 2000) then
Result := 'Medium'
else
Result := 'Large';
// Check if a score falls in a passing range
if IsBetween([Test.Score], 70, 100) then
Result := 'Pass'
else
Result := 'Fail';
Ln
Returns the natural logarithm (base e) of a number. The number must be greater than zero.
Ln(X: Extended): Extended
| Parameter | Type | Description |
|---|---|---|
| X | Extended | The number to evaluate (must be > 0) |
// Calculate compound annual growth rate (CAGR)
var cagr := Exp(Ln([Ending] / [Beginning]) / [Years]) - 1;
Result := FormatFloat('0.00"%"', cagr * 100);
Percent
Calculates a value as a percentage of a total. Returns 0 if the total is zero, avoiding a division by zero error.
Percent(Value, Total: Double): Double
| Parameter | Type | Description |
|---|---|---|
| Value | Double | The partial value |
| Total | Double | The total value |
// Show what percentage of total sales this product represents
Result := FormatFloat('0.00"%"', Percent([Item.Sales], [Report.TotalSales]));
// Display completion percentage
Result := FormatFloat('0"%"', Percent([Project.TasksDone], [Project.TasksTotal]));
// Show a customer's share of total revenue
Result := FormatFloat('0.00"%"', Percent([Customer.Revenue], [Report.TotalRevenue]));
Pi
Returns the mathematical constant Pi (approximately 3.14159265358979).
Pi: Extended
// Calculate the area of a circle
var area := Pi * [Circle.Radius] * [Circle.Radius];
Result := FormatNumberSafe(area, 2);
// Circumference
var circumference := 2 * Pi * [Circle.Radius];
Result := FormatNumberSafe(circumference, 2);
Random
Returns a random floating point number between 0 (inclusive) and 1 (exclusive). Call Randomize first to seed the random number generator, otherwise the same sequence will be produced each run.
Random: Extended
// Generate a random number between 1 and 100
Randomize;
var n := Trunc(Random * 100) + 1;
Result := IntToStr(n);
// Random percentage for testing
Result := FormatFloat('0.00"%"', Random * 100);
Randomize
Seeds the random number generator using the current time, ensuring a different sequence of random numbers each time the script runs. Always call this before using Random.
procedure Randomize
Randomize;
var roll := Trunc(Random * 6) + 1; // Simulate a dice roll (1-6)
Result := IntToStr(roll);
Round
Rounds a floating point number to the nearest integer using banker’s rounding (rounds to even on .5). For rounding to a specific number of decimal places see RoundTo2 and RoundToN.
Round(E: Extended): Integer
| Parameter | Type | Description |
|---|---|---|
| E | Extended | The number to round |
Result := IntToStr(Round(12.7));
// Returns: '13'
Result := IntToStr(Round(12.3));
// Returns: '12'
// Round a calculated quantity to a whole number
var qty := Round([Orders.Weight] / [Item.UnitWeight]);
Result := IntToStr(qty) + ' units';
RoundTo2
Rounds a number to exactly 2 decimal places. Useful for currency calculations where standard rounding to cents is required.
RoundTo2(V: Double): Double
| Parameter | Type | Description |
|---|---|---|
| V | Double | The number to round |
Result := FormatCurrencySafe(RoundTo2([Orders.Subtotal] * 1.07));
// Rounds tax-inclusive total to exactly 2 decimal places
// Round a calculated unit price before display
Result := FormatCurrencySafe(RoundTo2([Item.Cost] / [Item.UnitsPerCase]));
var tax := RoundTo2([Orders.Total] * [Tax.Rate]);
Result := FormatCurrencySafe(tax);
RoundToN
Rounds a number to a specified number of decimal places.
RoundToN(V: Double; N: Integer): Double
| Parameter | Type | Description |
|---|---|---|
| V | Double | The number to round |
| N | Integer | Number of decimal places |
Result := FormatNumberSafe(RoundToN([Item.Weight], 3), 3);
// Rounds to 3 decimal places: '12.456'
// Round a rate to 4 decimal places
Result := FormatNumberSafe(RoundToN([Finance.InterestRate], 4), 4);
// Round to whole number (0 decimals)
Result := IntToStr(Round(RoundToN([Stats.Average], 0)));
SafeDiv
Divides two numbers and returns 0 if the divisor is zero, avoiding a division by zero error. Use this whenever the denominator of a calculation may be zero.
SafeDiv(A, B: Double): Double
| Parameter | Type | Description |
|---|---|---|
| A | Double | The numerator |
| B | Double | The denominator |
// Average order value โ safe even when order count is zero
Result := FormatCurrencySafe(SafeDiv([Customer.TotalSales], [Customer.OrderCount]));
// Gross margin percentage โ safe when revenue is zero
Result := FormatFloat('0.00"%"', SafeDiv([Item.Profit], [Item.Revenue]) * 100);
// Cost per unit โ safe when quantity is zero
Result := FormatCurrencySafe(SafeDiv([Orders.TotalCost], [Orders.Quantity]));
Sin
Returns the sine of an angle given in radians.
Sin(E: Extended): Extended
| Parameter | Type | Description |
|---|---|---|
| E | Extended | Angle in radians |
var pi := ArcTan(1) * 4;
Result := FloatToStr(Sin(pi / 2));
// Returns: '1' (sine of 90 degrees)
Sqrt
Returns the square root of a number. The number must be zero or greater.
Sqrt(E: Extended): Extended
| Parameter | Type | Description |
|---|---|---|
| E | Extended | The number to evaluate (must be >= 0) |
Result := FormatNumberSafe(Sqrt(144), 0);
// Returns: '12'
// Standard deviation from variance
Result := FormatNumberSafe(Sqrt([Stats.Variance]), 2);
Tan
Returns the tangent of an angle given in radians.
Tan(X: Extended): Extended
| Parameter | Type | Description |
|---|---|---|
| X | Extended | Angle in radians |
var pi := ArcTan(1) * 4;
Result := FormatNumberSafe(Tan(pi / 4), 0);
// Returns: '1' (tangent of 45 degrees)
Trunc
Truncates a floating point number to an integer by discarding everything after the decimal point. Unlike Round, no rounding occurs โ the value is always truncated toward zero.
Trunc(E: Extended): Integer
| Parameter | Type | Description |
|---|---|---|
| E | Extended | The number to truncate |
Result := IntToStr(Trunc(12.99));
// Returns: '12' (not rounded up)
Result := IntToStr(Trunc(-12.99));
// Returns: '-12' (truncates toward zero)
// Convert a calculated number of weeks to whole weeks only
var weeks := Trunc(DaysBetweenSafe([Project.StartDate], Date) / 7);
Result := IntToStr(weeks) + ' complete weeks';