The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

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

Calculated Number field does not show decimal in result

Andy Ukasick
Contributor
September 7, 2018

Hi. I imagine the answer to this is very simple, but I'm so sort of java developer and I'm stuck. I have 4 single select fields where each option in the pick list is a number. They are whole numbers (ex: 1, 2, 3, 5, 8, 13 ...

I need to add 3 of them and then divide the result by the fourth field.  My problem is that I want the result to show the decimal value to one digit but it only returns whole numbers.

For ex:  (8 + 5 + 3) / 5 = 3.2  but my calc number field shows 3. When I tell it to format the result to one decimal it gives me 3.0 instead of 3.2.  Here's my formula:

<!-- @@Formula: 

if (issue.get("customfield_10899") == null) return null;
if (issue.get("customfield_10900") == null) return null;
if (issue.get("customfield_10901") == null) return null;
if (issue.get("customfield_10902") == null) return null;

((issue.get("customfield_10900") != null ? Integer.parseInt(issue.get("customfield_10900").toString()) : 0) +
(issue.get("customfield_10901") != null ? Integer.parseInt(issue.get("customfield_10901").toString()) : 0) +
(issue.get("customfield_10902") != null ? Integer.parseInt(issue.get("customfield_10902").toString()) : 0)) /
(issue.get("customfield_10899") != null ? Integer.parseInt(issue.get("customfield_10899").toString()) : 0)
-->

<!-- @@Format:
numberTool.format("0.0", value)
-->

 

Any help is greatly appreciated!

 

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

1 vote
Answer accepted
Tuncay Senturk _Snapbytes_
Community Champion
September 8, 2018

Hello,

In Java, default number conversion is int, so if you do not cast any of the variable to double you will loose the floating part.

Use Double.parseDouble for each or for at leas one. That should make the trick.

Or cast :  a + b + c / (double) d where a,b,c, and d are your Integer.parseInt statements.

Tuncay

AndyTestUser
Contributor
September 10, 2018

redacted

Andy Ukasick
Contributor
September 10, 2018

That did the trick!  Thank you!!

0 votes
Tuncay Senturk _Snapbytes_
Community Champion
September 10, 2018

Glad to hear that it worked