Search through more than a hundred articles on every aspect of User.com

Dawid Tyburek
Written by Dawid Tyburek

Simple calculations

See how to use your data in math operations


You might be in need of doing some simple calculations and present the result in the receiver inbox. Or you could even send your Lead an offer with the price with the tax calculated in it, here is how to do it!


Add

Adds the argument to the value

It can be as simple as:

Here is your final score: {{ receiver.points|add:"2" }}

Or a little bit more complex:

Total cost of the package: {{ receiver.purchase|add:receiver.shipping_method }}

When receiver.purchase is 5 and receiver.shipping_method is 10, total cost of the package will be 15.


Substraction

Substracts the argument from a value

It can be as simple as:

Here is your reduced price: {{ receiver.price|add:"-2" }}

Or a little bit more complex:

Your quote with discount applied: {{ receiver.price|add:receiver.discount }}

When receiver.price is 10 and receiver.discount is -2, quote with applied discount will be 8.


Multiply

To multiply values use {% widthratio x 1 y %}

{% widthratio 10 1 5 %}
it will print 50 as a result

You can use it with the value of your variables

{% widthratio receiver.purchase_price 1 receiver.amount_of_products %}

Or even save the result as a temporary variable

{% widthratio receiver.purchase_price 1 receiver.amount_of_products as final_price %}
Amount to pay: {{final_price}}

When receiver.purchase_price is 10 and receiver.number_of_products is 5 the amount to pay will be 50.


Divide

To divide values use {% widthratio x y 1 %}

{% widthratio 10 5 1 %}
It will print 2 as a result

You can use it with the value of your variables

{% widthratio receiver.purchase_price receiver.discount 1 %}

Or even save the result as a temporary variable

{% widthratio receiver.purchase_price receiver.discount 1 as final_price %}
Amount after discount: {{final_price}}

More complex usage is also possible

{% widthratio receiver.price 23 1 as tax %}
Amount to pay after tax: ${{ receiver.price|add:tax}}

When receiver.price is 2000, tax rate is 23% we can calculate amount to pay after tax to be $2087.




Please note that all of above calculations will coerce values to integers thus no floating point numbers are available as a result.

Related articles

Categories: