Roundings in calculations

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 ?

Hello,

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

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
  3. When it’s at position 3, the age is higher than 9
  4. Else it’s below 10
  5. Number of item 2 minus 1
  6. Cut the characters until 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” CHARACTERS → Result = “8.”
  3. Calculation: TEXT [Step 2] CONTAINS “.” → Result = “true”
  4. If there’s a “.” in the first two characters the age is below 10, which is true in this case
  5. Calculation: CUT [Step 1] FROM “1” FOR “1” CHARACTER → Result = “8”

Option number 3:

The concept behind option number 3 can be very useful 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 columns. 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 would be marked as importable (see 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 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)
    df28db4r5gf8magxr4b0oxu7ja5jjul71