Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to use .round in an automation that is also a calculation

Genevieve_Green January 31, 2023

I have created an automation to work out the average of 3 numerical fields.

 

Action is to update an "Outcome" field using the below formula:

{{#=}}{{issue.customfield_10679.asnumber.plus(issue.customfield_10680.asnumber.plus(issue.customfield_10681.asnumber))}} / 3 {{/}}

 

All 3 custom fields are Smalltext fields which default to 0 and are for us to enter a number 0-100 (how successful that criteria was).

 

The goal is this automation to to update the Outcome field with the output of that calculation, whenever Fields 1, 2 or 3 are edited.

 

eg. field 1 contains 25, field 2 contains 50 and field 3 contains 75.

the Outcome field should output 50, and does so correctly.

 

My issue is when the output is a decimal and returns very long, messy numbers.

 

I have seen the .round smart value but cannot seem to get it to work with my formula.

 

Could someone please advise how my formula should look to round the output down to the next whole number, or even to 1DP?

2 answers

1 accepted

0 votes
Answer accepted
Walter Buggenhout
Community Champion
January 31, 2023

Hi @Genevieve_Green,

I don't have a working environment where I can test, but given the complexity of your formula I suspect the best way to try and achieve what you're after may be through a ROUND() function.

Something like this:

ROUND(
{{#=}}{{issue.customfield_10679.asnumber.plus(issue.customfield_10680.asnumber.plus(issue.customfield_10681.asnumber))}} / 3 {{/}}
, 0)

That function is listed on the smart values, math expressions overview page and may even let you define the number of decimals to display.

Hope this helps!

Genevieve_Green February 1, 2023

Hi @Walter Buggenhout 

 

Thanks for the quick response.

 

I tried the string provided and it did not error but also did not produce a desired outcome.

 

Output field contained 

ROUND( 3.3333333333333335 , 0)

 

Instead of 3 or 3.33333333333 etc

Walter Buggenhout
Community Champion
February 1, 2023

Just trial and error to be honest, but maybe that's because the function should be inside the math tags at the beginning and end.

{{#=}}
ROUND({{issue.customfield_10679.asnumber.plus(issue.customfield_10680.asnumber.plus(issue.customfield_10681.asnumber))}} / 3, 0)
{{/}}

If that doesn't work, you may want to look at @Bill Sheboy's suggestion too. I know he's often providing great answers about automation stuff 😀 

Like # people like this
Genevieve_Green February 1, 2023

Hi @Walter Buggenhout 

 

That second string did the trick, it' now returning correctly and to the nearest whole number.

 

Something else to add to my bag of tricks for automations :)

 

Thank you!

Like Walter Buggenhout likes this
Walter Buggenhout
Community Champion
February 1, 2023

And to mine as well 😀 - thx for the heads up!

0 votes
Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 31, 2023

Hi @Genevieve_Green 

Have you tried to chain the entire expression, including the division by 3, such as with this:

{{issue.customfield_10679.asNumber.plus(issue.customfield_10680.asNumber).plus(issue.customfield_10681.asNumber).divide(3).round}}

And...do you expect any of the values to be empty (i.e. null)?  If so, considering adding a default value of zero to each with

.asNumber|0

Kind regards,
Bill

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events