Calculated Number field does not show decimal in result

Andy Ukasick 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

1 vote
Answer accepted
Tuncay Senturk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
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

Andrew Ukasick September 10, 2018

redacted

Andy Ukasick September 10, 2018

That did the trick!  Thank you!!

0 votes
Tuncay Senturk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 10, 2018

Glad to hear that it worked

Suggest an answer

Log in or Sign up to answer