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

how to check if divisible by 2 in <c:if>

 
Rajesh Khan
Ranch Hand
Posts: 230
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi i am trying to check a condition if its divisible by two using

but looks like % jstl doesn't recognize % any idea how i can check if something is divisible by two
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64192
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rajesh Khan wrote:
but looks like % jstl doesn't recognize % any idea how i can check if something is divisible by two

This has nothing to do with the JSTL but the EL.

And what evidence leads you to believe this?
 
Rajesh Khan
Ranch Hand
Posts: 230
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yep.. sorry I mean EL.
Any idea how i can check if a number is divisible by 2 using <c:if> tag ??
 
Devaka Cooray
ExamLab Creator
Marshal
Pie
Posts: 4117
195
Chrome Eclipse IDE Google App Engine IntelliJ IDE jQuery Postgres Database Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
% and mod are modulus operators in EL. In other words, it returns the result of the given modulo operation, which is NOT a boolean value.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64192
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How would you do it in Java? What makes you think you can't use %?
 
Stefan Evans
Bartender
Posts: 1640
9
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1 % 2 == 1
2 % 2 == 0
3 % 2 == 1
4 % 2 == 0
...
10 % 2 == 0
11 % 2 == 1

Perhaps the check you want is "count % 2 == 0" ?
In some languages a check of "if (count % 2)" is sufficient, because zero gets interpreted as false in that language.
This is not the case in EL though. You need to make the comparison to zero explicitly.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic