› Forums › Designer › Building applications › Roundings in calculations
 This topic has 4 replies, 3 voices, and was last updated 8 months, 2 weeks ago by Eddie Heijblom.
 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 ?
 Replies

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 31082020 – DOB 26092011 result = 9
Current date 31082020 – DOB 09072019 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:
 Show the age with more than 0 decimals
 Determine the age based on the first charachters, but it turns into a text field then
 Determine between which numbers the age lies and extract the nodecimalage from that (my preference, it’s easier to search for on table pages)
Option number 1:
Store the age in a dataitem 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:
 Convert it to a text
 Determine where the decimal is
 When it’s at position 3, the age is higher than 9
 Else it’s below 10
 Number of item 2 minus 1
 Cut the charachters untill the position in step 3
Let’s use an example for this. The age is 8.92
 Calculation: Use the function COMBINE “8.92” WITH “”(fill out nothing as a specific value in the second part)
 Calculation: CUT [Step 1] FROM “1” FOR “2” CHARACHTERS > Result = “8.”
 Calculation: TEXT [Step 2] CONTAINS “.” > Result = “true”
 If there’s a “.” in the first two charachters the age is below 10, which is true in this case
 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:
 Create a dataitem with two properties Age min and Age max with 0 decimals
 Create an Excel with 2 colums. Fill this Excel with corresponding ages
 Determine between which values the age lies
 Select the referenced/corresponding value
Let’s use an example for this. The age is 8.92
 Create the dataitem “Calculate age” with the properties “Age min” and “Age max” which are numbers with 0 decimals. This dataitem whould be marked as importable (see https://triggre.com/knowledgebase/creatingdataitems/ for more info)
 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 dataitem created in [Step 1]
PS: Use the wizard at Create User flows to create a user flow to import Excels (see https://triggre.com/knowledgebase/usingtheuserflowwizard/ for more info)  Import this Excel
 Create a lookup in your flow part and retrieve a single value. This lookup uses the following filter: [Input Age] >= [Age min] AND [Input Age] < [Age max]
 The age will be the [Age min] of the lookup. (see marked item in image below)
Tagged: #Roundings # age calculation
 The topic ‘Roundings in calculations’ is closed to new replies.