Class BirtMath
The BirtMath class provides functions to manipulate numeric data, for example, to add, subtract, multiple, divide, and round numbers. This class is static. The application cannot create instances of the class.
BirtMath.add
This function returns the sum of two numbers.
The first number to use in the calculation.
The second number to use in the calculation.
A number that results from adding n1 and n2.
The following example returns the sum of values in the SalesTotal and Shipping fields:
BirtMath.ceiling
This function rounds a number up, away from 0, to the nearest specified multiple.
A number that results from the rounding. If n is an exact multiple of significance, no rounding occurs.
BirtMath.ceiling( ) is commonly used to round up prices. For example, to avoid dealing with pennies, you can round prices in a Price field up to the nearest nickel with the following expression:
If the Price value is 20.52, the expression returns 20.55.
The following expression rounds prices up to the nearest dime:
If the Price value is 20.52, the expression returns 20.60. If the Price value is 20.40, the expression returns 20.40. No rounding occurs because 20.40 is a multiple of 0.1.
The following expression rounds prices up to the nearest dollar:
If the Price value is 20.30, the expression returns 21.
BirtMath.divide
This function returns the result of dividing one number by another.
The number by which dividend is divided.
A number that results from dividing dividend by divisor.
The following example shows the results of dividing specific numbers:
The following example returns the result of dividing values in the Total field by values in the Quantity field:
BirtMath.mod
This function returns the remainder after a number is divided by a divisor.
The number by which the first number is divided. You must specify a non-zero number.
The remainder after number is divided by divisor.
The following examples shows the results that the function returns for specific numbers:
The following example checks if numbers in the Grade field are odd or even. When the divisor is 2, the function returns 0 for even numbers, and 1 for odd numbers.
BirtMath.multiply
This function returns the multiplication of two numbers.
The first number to use in the calculation.
The second number to use in the calculation.
A number that results from multiplying n1 and n2.
The following example returns the result of multiplying values in the QuantityOrdered and PriceEach fields:
BirtMath.round
This function rounds a number to a specified number of digits.
The number of digits to round number to. If you omit this argument, the function assumes 0.
A number rounded to a specified number of digits.
The following examples shows the results that the function returns for specific numbers:
The following example rounds the values in the PriceEstimate field to return an integer:
BirtMath.roundDown
This function rounds a number down to a specified number of digits.
The number of digits to round number down to. If you omit this argument, the function assumes 0.
A number rounded down to a specified number of digits.
The following examples shows the results that the function returns for specific numbers:
The following example rounds down the values in the PriceEstimate field to return an integer:
BirtMath.roundUp
This function rounds a number up to a specified number of digits.
The number of digits to round number up to. If you omit this argument, the function assumes 0.
A number rounded up to a specified number of digits.
The following examples shows the results that the function returns for specific numbers:
The following example rounds up the values in the PriceEstimate field to return an integer:
BirtMath.safeDivide
This function returns the result of dividing one number by another, preventing a division by zero condition.
The number by which dividend is divided.
The value to return when divisor is zero.
A number that results from dividing dividend by divisor.
The following example shows the results that the function returns for specific numbers:
The following example returns the result of dividing values in the Revenue field by values in the Volume field. If the Volume value is 0, the function returns 0.
BirtMath.subtract
This function returns the result of subtracting one number from another.
The number from which to subtract.
The number to subtract from n1.
A number that results from subtracting n2 from n1.
The following example shows the results of subtracting specific numbers:
The following example returns the result of subtracting values in the Discount field from values in the Total field:
(c) Copyright Actuate Corporation 2009 |