Skip to main content Link Search Menu Expand Document (external link)

- : 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

<p>Discount: $</p>

Data:

doc.Params["model"] = new {
    originalPrice = 99.99m,
    salePrice = 79.99m
};

Output:

<p>Discount: $20</p>

Calculating Remaining Stock

<p>Remaining:  units</p>

Data:

doc.Params["model"] = new {
    totalStock = 500,
    soldQuantity = 347
};

Output:

<p>Remaining: 153 units</p>

Date Difference (with days)

<p>Days remaining: </p>

Variance Calculation

<p>Variance: </p>

  <span class="positive">Above target</span>

  <span class="negative">Below target</span>

Data:

doc.Params["model"] = new {
    actual = 125000m,
    expected = 100000m
};

Output:

<p>Variance: 25000</p>
<span class="positive">Above target</span>

Combined with Other Operators

<!-- Discount percentage -->
<p>Save: %</p>

<!-- Net profit -->
<p>Profit: $</p>

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()

See Also