 # Roundings in calculations

Forums Designer Building applications Roundings in calculations

• Post

I have made a calculation based on dates to calculate an age of somebody.

I use the current date – birthdate. Although is probably not the most accurate, it works wouldn’t it that Triggre uses roundings. Is there a way to solve this ?

Viewing 4 replies - 1 through 4 (of 4 total)
• Replies

Hello Steven,

Could you provide me with an example?

I have a DB (Child) with the following fields: Name / date of birth / Place of birth / Age.

In a user flow I do the following:

Start with the DB Child -> step 1 -> calculation ( Current date – date of birth)

step2 -> Calculation (result step 1 / 1 days) = convert the value in to days

step 3 -> Calculation (result step 2 / 365,33) = age in years

step 4 -> edit data (field age / DB Child) with the value from step 3.

Example:

Current date 31-08-2020 – DOB 26-09-2011 result = 9

Current date 31-08-2020 – DOB 09-07-2019 result = 1

The second one is correct, but the first example is not 9 yet

Hi Steven,

What you could do is the following:

1) Create a number field with 2 decimals. The result will be less than 9.

2) Consequently convert the number to a text by using the function “combine A with B”. (A= number from step 4, B = empty text)

3) Calculate the number of characters minus number of decimals and comma in a calculation (so, in the case of two decimals (-2 + -1 = -3) )

4)Use the function “Cut A from B for n characters”. A = new textfield, B=1, n= Calculate the number of characters minus number of decimals and comma.

5) Create a new textfield in your datamodel and save there the outcome of step 4.

Will this help?

-Jochem

Steven,

Rounding is automatically executed in Triggre. In the first case the value will be something like 8.92 which is rounded to 9. Which is a standard rounding. To get the result you’re looking for you have three options:

1. Show the age with more than 0 decimals
2. Determine the age based on the first charachters, but it turns into a text field then
3. Determine between which numbers the age lies and extract the no-decimal-age from that (my preference, it’s easier to search for on table pages)

Option number 1:

Store the age in a data-item with a property with more than 0 decimals.

Option number 2:

Let’s assume someone can’t get older than 99, for this example. You can extend this to > 100 by adding another decision to your flow part.

We need to do the following steps:

1. Convert it to a text
2. Determine where the decimal is
1. When it’s at position 3, the age is higher than 9
2. Else it’s below 10
3. Number of item 2 minus 1
4. Cut the charachters untill the position in step 3

Let’s use an example for this. The age is 8.92

1. Calculation: Use the function COMBINE “8.92” WITH “”(fill out nothing as a specific value in the second part)
2. Calculation: CUT [Step 1] FROM “1” FOR “2” CHARACHTERS -> Result = “8.”
3. Calculation: TEXT [Step 2] CONTAINS “.” -> Result = “true”
4. If there’s a “.” in the first two charachters the age is below 10, which is true in this case
5. Calculation: CUT [Step 1] FROM “1” FOR “1” CHARACHTER -> Result = “8”

Option number 3:

The concept behind option number 3 can be very usefull in other situations as well. The general idea behind it is that we look up the value in a table and use a referenced value linked to that table.

We need to do the following steps:

1. Create a data-item with two properties Age min and Age max with 0 decimals
2. Create an Excel with 2 colums. Fill this Excel with corresponding ages
3.  Determine between which values the age lies
4. Select the referenced/corresponding value

Let’s use an example for this. The age is 8.92

1. Create the data-item “Calculate age” with the properties “Age min” and “Age max” which are numbers with 0 decimals. This data-item whould be marked as importable (see https://triggre.com/knowledge-base/creating-data-items/ for more info)
2. Create an Excel. This Excel has two columns “Age min” and “Age max”. Also the name of the work sheet should be exactly the same as the name of the data-item created in [Step 1]
PS: Use the wizard at Create User flows to create a user flow to import Excels (see https://triggre.com/knowledge-base/using-the-user-flow-wizard/ for more info)
3. Import this Excel
4. Create a look-up in your flow part and retrieve a single value. This look-up uses the following filter: [Input Age] >= [Age min] AND [Input Age] < [Age max]
5. The age will be the [Age min]  of the look-up. (see marked item in image below) Viewing 4 replies - 1 through 4 (of 4 total)
• The topic ‘Roundings in calculations’ is closed to new replies.