IF / ELSE condition on Expression in Jasperreports

Asked

Viewed 1,429 times

0

I need to perform a field check expression in my report created in Jasperreports studio, my situation is as follows, I need to realize the following account:

$F{quantidade}/($F{quinze}/15.0)

But sometimes the count ($F{quinze}/15.0) results in zero, and it is not possible to carry out a division by zero, for this reason ends up being displayed in my report the symbol of infinity, my need is to verify if the account ($F{quinze}/15.0) result in 0 I want to change the return so it’s just $F{quantidade} and not the result of the account

2 answers

2


Just looking at the documentation, I made this formula using ternary operation, see if it fits your problem:

(($F{quinze}/15.0 == 0) ? $F{quantidade} : ($F{quantidade}/($F{quinze}/15.0)))

-2

$F{quinze} == 0 ? $F{quantidade} : $F{quantidade}/($F{quinze}/15.0)

it is still possible to add other conditions in the "if" with the operators || (or) and && (and)

Just don’t forget to circle the condition in parentheses if there are more than one, or you will have problems. being just a condition there is no problem in leaving out of the parenthesis, even I think it gets visually less polluted

Browser other questions tagged

You are not signed in. Login or sign up in order to post.