# Formulas - Math Updated by Judit

If this is your first time using Formulas, please check our Getting Started guide here and our crash course here

Use the Math formulas if you need to make calculations in your chatbot!

Read this article for some practical examples of how to use all the different Math Formulas available within Landbot.

• Product
• Quotient
• Remainder
• Subtract
• Sum
• ToFloat
• ToInteger
• Power
• Round
• Trunc

#### Product

This math formula, multiplies all the numbers given as arguments and returns the product.

Below you will see how the formula will look like when you apply a 20% discount:

`Product(@price, 0.8)`

#### Quotient

This math formula divides one number by another.

Below, you will see how the formula has to look like if you want to get % of correct answers.

`Quotient(Product(@correctanswers,100),@maxpoints)`

#### Remainder

This math formula gets the remainder from dividing two numbers received.

Below, you will see how to test if an integer is divisible by another number.

The "@integer" has the value "1128" and "@number" has the value "4". Since the remainder equals 0, it is divisible.

`Remainder(@integer,@number)`

#### Subtract

This math formula substracts all the numbers given as arguments and returns the result.

Below you see the formula to check how much products are left in stock

`Subtract(@total_items,@purchased_items)`

#### Sum

This math formula sums all the numbers given as arguments and returns the result.

Below you see the formula to add +1 every time user passes through this step

`Sum(@counter,1)`

#### ToFloat

This math formula converts a string or integer to a floating point number.

Below you see the formula to convert an integer to a floating point number where the variable @integer has the value 1015 and we want 1015.0

`ToFloat(@integer)`

#### ToInteger

This math formula converts a string or number to an integer.

Convert to only 2 decimals

Below is a formula where the variable @number has the value of 3.1415 and we only want 3.14

`Quotient(ToInteger(Product(@number, 100)),100)`

In case we want 1 decimal the Formula would be with 10:

`Quotient(ToInteger(Product(@number, 10)),10)`

To round up number and leave it without decimals:

`Sum(Quotient(ToInteger(Product(@number, 1)),1),1)`

Get age based on date selected

Below is a formula where the variable @datepicker is the value coming from the datepicker (the format should be DD/MM/YYYY or MM/DD/YYYY) with this flow:

And the Formula:

`ToInteger(Quotient(    Subtract(      Sum(        Product(GetValue(Split(ToString(&date[today]),"-"),0),360),Product(GetValue(Split(ToString(&date[today]),"-"),1),30),Product(GetValue(Split(ToString(&date[today]),"-"),2),1)),      Sum(  			Product(GetValue(Split(Replace(@datepicker,"/","-"),"-"),0),360),Product(GetValue(Split(Replace(@datepicker,"/","-"),"-"),1),30),Product(GetValue(Split(Replace(@datepicker,"/","-"),"-"),2),1))),360))`

The age, will be stored in the variable @age, as in the picture, you can use it after in a Conditional block.

#### Power

This math formula calculates a number raised to a power.

Compound interest

Let's say we want to calculate a compound interest:

M = C (1 + i)​n

Instead of using letters we will use variables:

@result = @capital (1 + @rate)​@numberofperiods

Here is how we will make the Formula:

`Product(  @capital,  Power(    Sum(1,@rate),    @numberofperiods  ))`

#### Round

This math formula round the numbers.

Round number to one decimal

What to do If you want to leave large numbers with just 1 decimal

`Round(@number,1)`

#### Trunc

This math formula cuts off the dot and the digits to the right of a number.

Get a number without decimals

`Trunc(@number)`

#### Random

Create a random number

Random number between 1-10:

`Random(1,10)`

### How did we do?

#### Formulas - Object 