pennywise Posted November 25, 2009 Share Posted November 25, 2009 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 More sharing options...
cn73 Posted November 25, 2009 Share Posted November 25, 2009 Master report-> (VARIABLEA == null ? 0 : VARIABLEA) +VARIABLEB+VARIABLEC Link to comment Share on other sites More sharing options...
pennywise Posted November 25, 2009 Author Share Posted November 25, 2009 VARIABLE A is double, i can't use ==, i tryed using variableA.intvalue() < 0 but i doesn't works, :( Link to comment Share on other sites More sharing options...
pennywise Posted November 25, 2009 Author Share Posted November 25, 2009 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 More sharing options...
flame113 Posted November 26, 2009 Share Posted November 26, 2009 You can also try to import a Formatter class. For example:public String format(Double value) { String result = "0"; if (value != null) { DecimalFormat formatter = new DecimalFormat("#,##0.00"); result = formatter.format(value); } return result;} Link to comment Share on other sites More sharing options...
pennywise Posted November 26, 2009 Author Share Posted November 26, 2009 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 doif(varA.lenght<0){make something}else{make this} Link to comment Share on other sites More sharing options...
cn73 Posted November 26, 2009 Share Posted November 26, 2009 ????? 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 More sharing options...
pennywise Posted November 26, 2009 Author Share Posted November 26, 2009 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 More sharing options...
cn73 Posted November 26, 2009 Share Posted November 26, 2009 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now