Jump to content

How replace null with 0


pennywise

Recommended Posts

 Hi everyone, i have a variable wich sum a field, but when i don't have registers in the field the report show null in the variable, so i need to show 0 when i don't have register, that because i use that variable is in a subreport and i use it in a master report to make another num;

 

subreport-> VARIABLE A = null

 

Master report->  VARIABLEA+VARIABLEB+VARIABLEC

 

if VARIABLEA = null master report show null, it doesn't matter if there are values in B or C :(, that's my problem

Link to comment
Share on other sites

  • Replies 8
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

 I tryed this:

 

($V{variableA}.doubleValue() < 0 ? 0 : $V{variableA})+($V{variableB}.doubleValue() < 0 ? 0 : $V{variableB})+($V{variableC}.doubleValue() < 0 ? 0 : $V{variableC})

 

but there is an exeption:

 

Incompatible conditional operands types int and double

 

Link to comment
Share on other sites

 You said using scriplets?

 

Wel i think i can resolve this issue if i know how make if else in jasperreports, is not clear how to do this,

I know if is =

 

(<condition> expre1 ? expre 2 :)

but else?

 

how you do a normal if-else block on jasperreports, for example to do

if(varA.lenght<0){

make something

}else{

make this

}

Link to comment
Share on other sites

????? every Object can tested with == null... include Double type...

 

then:

if(varA.lenght<0){

make something

}else{

make this

}

is perfectly equal to

 

(varA.lenhth<0 ? make something : make this)



Post Edited by cn73 at 26/11/2009 15:02
Link to comment
Share on other sites

Ahhhhh, i see, well when i tryed use == null it show a exception, maybe is the form how i use it, how you make a condition using null, and how is the or sintaxys:

 

for example:

 

if varA==null and varA.lenght < 0 -> how is the equivalent in jasperreports

 

thanks all for your reply

 

Link to comment
Share on other sites

attention! if varA == null and you attempt varA.length... you have a NullPointerException!

 

you mean:

 

if (varA != null && varA.length() == 0) ??

 

When Java evaluates the expression d = b && c;, it first checks whether b is true. Here b is false, so b && c must be false regardless of whether c is or is not true, so Java doesn't bother checking the value of c.

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...