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!
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.