If / then visible or not visible question


Hello all - hoping someone in the group can help.

We utilize Jaspersoft Studio with our inventory database to print sale tags and signs for our store depending on different weekly sales plans.  Recently, our inventory software was updated to include divider price numbers so that we can price items at 3/$5.00, for example, instead of $1.66.  This new element has made it a bit more of a challenge to create multiple signs using Jaspersoft when there is a mixture of single priced items as well as multiple priced items.

Looking for the Jaspersoft code that would do the following:

Database elements:  Price Divider, Price.   Container is a box on one portion of the sign / report

If Price Divider is equal to 1, print just the Price value centered in the container

If Price Divider is greater than 1, print the Price Divider, then " / ", then the Price with all three centered in the container.


Depending on those variables, we would get 



3 / 5.00

Thank you in advance for any assistance you can give.

cwhiton's picture
Joined: Apr 7 2019 - 1:03pm
Last seen: 1 year 2 months ago

1 Answer:


Just use the ternary operator.

$F{id} == 1 ? $F{price} : $F{price_divider} + " / " + $F{price}


($F{id}== 1 ? "": $F{price_divider} + " / ") + $F{price}

You'll need to format price your self. 


($F{id}== 1 ? "": $F{price_divider} + " / ") + NumberFormat.getCurrencyInstance().format($F{price})

hozawa's picture
Joined: Apr 24 2010 - 4:31pm
Last seen: 1 year 3 weeks ago