This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

If value is Null then 0.00

 
Dan Acuff
Ranch Hand
Posts: 62
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 12021
25
Chrome Java Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Dan Acuff
Ranch Hand
Posts: 62
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20380
46
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are many ELs; JSP EL, Unified EL, MVEL, OGNL, ... Any of which can be used outside of JSP.
 
Rob Spoor
Sheriff
Pie
Posts: 20380
46
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah ok.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47262
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic