Viewer Math Helpers
This page explains common math helpers you can use in Viewer templates.
Use these helpers to calculate values directly in your template output, such as totals, discounts, percentages, and rounded numbers.
Function name meaning (quick reference)โ
add= add two numberssubtract= subtract one number from anothermultiply= multiply numbersdivide= divide one number by anothermodulo= get the remainder after divisionround= round to nearest whole numberfloor= round downceil= round up
addโ
Adds numbers.
Scenario: Show amount + shipping in one line.
Expected result: 1350
subtractโ
Subtracts one number from another.
Scenario: Show amount after discount.
Expected result: 1050
multiplyโ
Multiplies numbers.
Scenario: Calculate line total from quantity and unit price.
Expected result: 1000
divideโ
Divides one number by another.
Scenario: Show amount per month from annual value.
Expected result: 100
moduloโ
Returns the remainder of a division.
Scenario: Check remainder for installment split display.
Expected result: 1
roundโ
Rounds to the nearest whole number.
Scenario: Display cleaner percentage values.
Expected result: 19
floorโ
Rounds down to the nearest whole number.
Scenario: Conservative quantity display.
Expected result: 18
ceilโ
Rounds up to the nearest whole number.
Scenario: Ensure minimum whole-unit billing.
Expected result: 19
Practical end-to-end exampleโ
Use math helpers to build a simple pricing summary:
Math helper tipsโ
- Keep calculations short and readable.
- Prefer direct Salesforce fields in examples.
- Round values for customer-facing documents when needed.
- If an expression becomes long, split it into multiple output lines.
Common Use Casesโ
How do I calculate a total from multiple fields?โ
Use add to combine values:
Result: 1,350 (from 1,200 + 150)
How do I show an amount after applying a discount?โ
Use subtract to calculate net amounts:
Result: 1,050 (from 1,200 - 150)
How do I calculate line item totals (quantity ร unit price)?โ
Use multiply for line calculations:
Result: 1,000 (from 8 ร 125)
How do I convert annual amounts to monthly?โ
Use divide for period splits:
Result: 100 (from 1,200 รท 12)
How do I round a percentage or probability value?โ
Use round to simplify decimals:
Result: 19% (from 18.6)
How do I ensure a value rounds up for billing purposes?โ
Use ceil for conservative rounding:
Result: 19 (from 18.1)