Skip to main content

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 numbers
  • subtract = subtract one number from another
  • multiply = multiply numbers
  • divide = divide one number by another
  • modulo = get the remainder after division
  • round = round to nearest whole number
  • floor = round down
  • ceil = round up

addโ€‹

Adds numbers.

Scenario: Show amount + shipping in one line.

add example: amount + shipping
{{add Opportunity.Amount Opportunity.Shipping_Cost__c}}
add with actual number
{{add 1200 150}}

Expected result: 1350

subtractโ€‹

Subtracts one number from another.

Scenario: Show amount after discount.

subtract example: net amount
{{subtract Opportunity.Amount Opportunity.Discount_Amount__c}}
subtract with actual number
{{subtract 1200 150}}

Expected result: 1050

multiplyโ€‹

Multiplies numbers.

Scenario: Calculate line total from quantity and unit price.

multiply example: line total
{{multiply Opportunity_Product_Quantity__c Opportunity_Product_UnitPrice__c}}
multiply with actual number
{{multiply 8 125}}

Expected result: 1000

divideโ€‹

Divides one number by another.

Scenario: Show amount per month from annual value.

divide example: monthly amount
{{divide Opportunity.Annual_Value__c 12}}
divide with actual number
{{divide 1200 12}}

Expected result: 100

moduloโ€‹

Returns the remainder of a division.

Scenario: Check remainder for installment split display.

modulo example: remainder
{{modulo Opportunity.Total_Items__c 3}}
modulo with actual number
{{modulo 10 3}}

Expected result: 1

roundโ€‹

Rounds to the nearest whole number.

Scenario: Display cleaner percentage values.

round example: percentage
{{round Opportunity.Win_Probability__c}}
round with actual number
{{round 18.6}}

Expected result: 19

floorโ€‹

Rounds down to the nearest whole number.

Scenario: Conservative quantity display.

floor example: round down
{{floor Opportunity.Estimated_Users__c}}
floor with actual number
{{floor 18.9}}

Expected result: 18

ceilโ€‹

Rounds up to the nearest whole number.

Scenario: Ensure minimum whole-unit billing.

ceil example: round up
{{ceil Opportunity.Estimated_Seats__c}}
ceil with actual number
{{ceil 18.1}}

Expected result: 19

Practical end-to-end exampleโ€‹

Use math helpers to build a simple pricing summary:

Pricing summary example
Base amount: {{Opportunity.Amount}}
Discount amount: {{Opportunity.Discount_Amount__c}}
Net amount: {{subtract Opportunity.Amount Opportunity.Discount_Amount__c}}
Tax (18%): {{multiply (subtract Opportunity.Amount Opportunity.Discount_Amount__c) 0.18}}
Grand total: {{add (subtract Opportunity.Amount Opportunity.Discount_Amount__c) (multiply (subtract Opportunity.Amount Opportunity.Discount_Amount__c) 0.18)}}

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:

Grand Total: {{add Opportunity.Amount Opportunity.Shipping_Cost__c}}

Result: 1,350 (from 1,200 + 150)

How do I show an amount after applying a discount?โ€‹

Use subtract to calculate net amounts:

Net Amount: {{subtract Opportunity.Amount Opportunity.Discount_Amount__c}}

Result: 1,050 (from 1,200 - 150)

How do I calculate line item totals (quantity ร— unit price)?โ€‹

Use multiply for line calculations:

Line Total: {{multiply Opportunity_Product_Quantity__c Opportunity_Product_UnitPrice__c}}

Result: 1,000 (from 8 ร— 125)

How do I convert annual amounts to monthly?โ€‹

Use divide for period splits:

Monthly Amount: {{divide Opportunity.Annual_Value__c 12}}

Result: 100 (from 1,200 รท 12)

How do I round a percentage or probability value?โ€‹

Use round to simplify decimals:

Win Probability: {{round Opportunity.Win_Probability__c}}%

Result: 19% (from 18.6)

How do I ensure a value rounds up for billing purposes?โ€‹

Use ceil for conservative rounding:

Billable Units: {{ceil Opportunity.Estimated_Seats__c}}

Result: 19 (from 18.1)

More resourcesโ€‹