# Formulas - Math

Updated by Dilyara

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

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

#### Product

##### Apply 20% discount
`Product(@price, 0.8)`

#### Quotient

##### Get % of correct answers
`Quotient(Product(@correctanswers,100),@maxpoints)`

#### Remainder

##### Test if an integer is divisible by another number

In the formula below the @integer has the value 1128 and @number has the value 4. Since the remainder is equals to 0, it is divisible.

`Remainder(@integer,@number)`

#### Subtract

##### Check how much products are left in stock
`Subtract(@total_items,@purchased_items)`

#### Sum

##### Add +1 every time user passes through this step
`Sum(@counter,1)`

#### ToFloat

##### Convert an integer to a floating point number

Below is a formula where the variable @integer has the value 1015 and we want 1015.0

`ToFloat(@integer)`

#### ToInteger

##### 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

##### 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

##### Round number to one decimal

If you want to finish large numbers with only 1 decimal:

`Round(@number,1)`

#### Random

Create a random number

Random number between 1-10:

`Random(1,10)`

#### Trunc

##### A number without decimals

`Trunc(@number)`