- : Subtraction Operator
On this page
Summary
Subtract one numeric value from another.
Syntax
Precedence
Priority level in expression evaluation (1 = highest, 10 = lowest): 5
Evaluated after: ^, *, /, %
Evaluated before: <, <=, >, >=, ==, !=, ??, &&, ||
Operands
| Position | Type | Description |
|---|---|---|
| Left | Number | The value to subtract from (minuend) |
| Right | Number | The value to subtract (subtrahend) |
Returns
Type: Number (Int, Long, Double, or Decimal depending on operands)
The difference between the left and right operands.
Examples
Basic Subtraction
Data:
doc.Params["model"] = new {
originalPrice = 99.99m,
salePrice = 79.99m
};
Output:
<p>Discount: $20</p>
Calculating Remaining Stock
Data:
doc.Params["model"] = new {
totalStock = 500,
soldQuantity = 347
};
Output:
<p>Remaining: 153 units</p>
Date Difference (with days)
Variance Calculation
Data:
doc.Params["model"] = new {
actual = 125000m,
expected = 100000m
};
Output:
<p>Variance: 25000</p>
<span class="positive">Above target</span>
Combined with Other Operators
Notes
- Works with all numeric types (int, long, double, decimal)
- Result type depends on operand types (follows C# numeric promotion rules)
- Use parentheses to control order of operations
- For absolute difference, use
abs(a - b) - Cannot subtract non-numeric types
- Date subtraction should use date/time functions like
daysBetween()