jQuery in Action, 2nd edition
The moose likes Other Languages and the fly likes If value is Null then 0.00 Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Other Languages » Other Languages
Reply 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: 60
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: 8104

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


Never ascribe to malice that which can be adequately explained by stupidity.
Dan Acuff
Ranch Hand

Joined: Jul 13, 2009
Posts: 60
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!

This message was edited 1 time. Last update was at by Campbell Ritchie

David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12612
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
Saloon Keeper

Joined: Oct 27, 2005
Posts: 17259

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
How To Ask Questions How To Answer Questions
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12612
There are many ELs; JSP EL, Unified EL, MVEL, OGNL, ... Any of which can be used outside of JSP.
Rob Spoor
Saloon Keeper

Joined: Oct 27, 2005
Posts: 17259

Ah ok.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 25057
David Newton wrote: . . . which forum should it be in?
Let's try for another forum

This message was edited 1 time. Last update was at by Campbell Ritchie

 
 
subject: If value is Null then 0.00
 
WebSphere development made easy
without the weight of IBM tools
http://www.myeclipseide.com