File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Other Languages and the fly likes If value is Null then 0.00 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Languages » Other Languages
Bookmark "If value is Null then 0.00" Watch "If value is Null then 0.00" New topic
Author

If value is Null then 0.00

Dan Acuff
Ranch Hand

Joined: Jul 13, 2009
Posts: 62
Am I doing the syntax correctly here?

It is supposed to subtract the discount value from the subtotal. But I am not getting any results. I have also tried '' in place of null.



:banghead:
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11249
    
  16

the ternary operator should look like this:

boolean ? type : type

so...is customerSession.receiptOrder.discount a boolean? My guess is that it's not, but I can't tell from this code snippet.

The two things you might return should be the same...and int and an int, or a string and a string. 'null' (I think) can be anything, so it probably works in place of a float, which is what you get with your 0.0.

In short, I don't think this is right. I thing you want something like

customerSession.receiptOrder.discount is null ? 0.0 : customerSession.receiptOrder.discount


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Dan Acuff
Ranch Hand

Joined: Jul 13, 2009
Posts: 62
Ahh a ternary operator is what it is called huh... nice.

Thanks for getting me straightened out, I came up with this working expression.




Thanks for your help!
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

I'm confused. Is this Java? It doesn't look like Java. It looks more like some sort of EL. In any case, which forum should it be in?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19674
    
  18

EL is JSP, isn't it? But I can't remember seeing "var" in EL (but then again, it's been a while). I first thought it was JavaScript but the # and eq aren't part of that.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

There are many ELs; JSP EL, Unified EL, MVEL, OGNL, ... Any of which can be used outside of JSP.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19674
    
  18

Ah ok.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38441
    
  23
David Newton wrote: . . . which forum should it be in?
Let's try for another forum
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: If value is Null then 0.00