Arithmetic

Perform simple calculations with two numbers. It also shares the same parameters as View Formatted Number and uses your Number Format Defaults. If you are passing variables (eg. {my_variable}) in as parameters pay close attention to variable parse order. If you are having problems with a calculation, use the debug parameter to see what is being processed.

Table of Contents

Parameters

expression

Enter a full arithmetic expression. If this parameter is used, the others are ignored.

expression="{quantity} * {price}"
operator

Valid operators are: +, -, *, /, ++, and --.

operator="*"
num1

Required if not using expression param. All non-numeric characters will be stripped.

num1="{price}"
num2

Required, if not using expression param and operator is neither ++ nor --.

num2="{quantity}"
debug

If using the expression param, setting this to "yes" will print out the expression rather than evaluate it. This can help debugging parse order issues.

debug="yes"
format

Setting this to "yes" will print out the expression as a formatted currency vs. a raw integer/float.

format="yes"

Examples

Item Subtotal: {exp:cartthrob:arithmetic expression="{item:quantity} * {item:price}"}

// Result: 1.23

Item Subtotal: {exp:cartthrob:arithmetic expression="{item:quantity} * {item:price}"}

// Result $1.23

Item Subtotal: {exp:cartthrob:arithmetic operator="*" num1="{item:quantity}" num2="{item:price}"}

// Result: 1.23