Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,410,317
Community Members
 
Community Events
169
Community Groups

JIRA Misc Custom Fields plugin - formatting?

I'm using the JIRA Misc Custom Fields plugin within Confluence to calculate some things between other custom fields. The result of the equation is a float, which display just fine, however I want to be able to format the output so that it only shows 2 decimal places.

Not being a java bod in any shape or form, could somebody tell me how I would force the format to 2 decimal places please?

2 answers

1 accepted

2 votes
Answer accepted

Figured it out - the code is not what I am intending to do, just a simple way of proving that I can do something more complex. =)

<!-- @@Formula: 

import java.text.DecimalFormat;
import java.text.NumberFormat;

double estDiff = 0; 

estDiff = issue.get("timeestimate");
estDiff = estDiff / 3600;

NumberFormat formatter = new DecimalFormat("#0.00");

return formatter.format(estDiff);

-->

0 votes

It's not something you can do in the UI I'm afraid.

If you were willing to pull apart the plugin and recompile it, you can do it with a bit of "velocity" - these are templates which determine the html that comes out. The result you're seeing is probably rendered with a simple "if $value, then show $value" type line of code, which you could change to "if $value, then show $value.format("%.2g%n") "

Or you might try injecting some javascript to format it as the browsers render it (I'm less sure on the code for that)

The documentation for the plugin states it can be formatted ...

Custom formatting

You can also specify custom formatting for the value of the Calculated Number field. In the Description field, add your formatting formula using the following syntax:

<!-- @@Format: formula goes here -->

The formula itself is a Java-style expression that can reference the value returned by the formula using the value variable. You can also use the numberTool object to format the number value:

numberTool.format(value)
<h6>Example</h6>

To display an icon to the left of the field value depending on the field value:

<!-- @@Format:
if (value > 21)
return "<img src='/images/icons/priority_trivial.gif'> "+numberTool.format(value);
else if (value >= 10)
return "<img src='/images/icons/priority_major.gif'> "+numberTool.format(value);
else
return "<img src='/images/icons/priority_blocker.gif'> "+numberTool.format(value);
-->

I just can't figure it out - at least, not in the amount of time I have :-(

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events