Performance Testing (PTS) provides built-in arithmetic operations for dynamic value computation during test execution.
Operation categories
| Category | Operations | Default decimal handling |
|---|---|---|
| Basic arithmetic | Addition, subtraction, multiplication, division (basic) | Rounds to 2 decimal places (round-half-up) |
| Advanced division | Division (advanced) | Configurable decimal places and rounding mode |
| Rounding | scale() function | Configurable decimal places and rounding mode |
Basic arithmetic
Addition, subtraction, multiplication, and division (basic) round decimal results to 2 decimal places by default, using the round-half-up method (ROUND_HALF_UP, mode 4).
| Expression | Raw result | Rounded result |
|---|---|---|
1.234 * 5 | 6.170 | 6.17 |
1 / 5 | 0.200 | 0.20 |
Control decimal precision
Division (advanced) and the scale() function let you control the number of decimal places and the rounding behavior. Both accept two parameters: the number of decimal places to retain and the rounding mode.
scale() syntax
scale(<decimal_places>, <round_mode>)| Parameter | Description |
|---|---|
decimal_places | Number of decimal places to retain. |
round_mode | Rounding mode identifier (0--6). See the Rounding modes section below. |
Example: scale(1, 2) retains 1 decimal place using ROUND_CEILING mode (round_mode=2).
Rounding modes
PTS supports seven rounding modes, aligned with the Java BigDecimal rounding constants.
Note
The following examples assume 2 decimal places.
round_mode | Java constant | Direction | Positive example | Negative example |
|---|---|---|---|---|
0 | ROUND_UP | Away from zero | 1.234 → 1.24 | -1.234 → -1.24 |
1 | ROUND_DOWN | Towards zero (truncate) | 1.234 → 1.23 | -1.234 → -1.23 |
2 | ROUND_CEILING | Towards positive infinity | 1.234 → 1.24 | -1.234 → -1.23 |
3 | ROUND_FLOOR | Towards negative infinity | 1.234 → 1.23 | -1.234 → -1.24 |
4 | ROUND_HALF_UP | Nearest neighbor; if equidistant, away from zero. If both neighbors are equidistant, behaves like mode 0. Otherwise, behaves like mode 1. | 1.235 → 1.24 | -1.235 → -1.24 |
5 | ROUND_HALF_DOWN | Nearest neighbor; if equidistant, towards zero. If both neighbors are equidistant, behaves like mode 1. Otherwise, behaves like mode 0. | 1.235 → 1.23 | -1.235 → -1.23 |
6 | ROUND_HALF_EVEN | Nearest neighbor; if equidistant, towards even digit (banker's rounding) | 1.235 → 1.24 | 1.245 → 1.24 |
Choose a rounding mode
| Use case | Recommended mode | Reason |
|---|---|---|
| General-purpose rounding | 4 (ROUND_HALF_UP) | Standard "round half up" behavior that most developers expect. |
| Financial calculations | 6 (ROUND_HALF_EVEN) | Banker's rounding minimizes cumulative rounding bias. |
| Always round up (absolute value) | 0 (ROUND_UP) | Rounds away from zero regardless of sign. |
| Always truncate | 1 (ROUND_DOWN) | Discards extra digits without rounding. |
| Sign-dependent rounding | 2 (ROUND_CEILING) or 3 (ROUND_FLOOR) | Ceiling rounds towards positive infinity; floor rounds towards negative infinity. |