3

I have this strange behavior in my JSP page:

I have two Integer variables count and size.

When I print the values of these variables to the page I'm getting

266 100

but when I use ${count div size} or ${count / size} I'm getting 2.66.

I checked that these both are Integers, also I put them to model, then retrieved in JSP (according to this answer) and printed class names to the JSP and they are Integers.

I know, I can write custom function, but why when that should work?

Community
  • 1
  • 1
Betlista
  • 10,327
  • 13
  • 69
  • 110

2 Answers2

2

For your specific case, the EL Spec mandates that both operands should be coerced to Double before the operator is applied.

kschneid
  • 5,626
  • 23
  • 31
  • I do not know why is this case specific, but you are right I found [here](http://jsp.java.net/spec/jsp-2_1-fr-spec-el.pdf) in chapter 1.7.2, that **Otherwise, coerce both A and B to Double and apply operator**, really strange, in mod operator Long is used. – Betlista Jun 15 '12 at 13:31
1

try <fmt:formatNumber value="${..} maxFractionDigits="0" />

Bozho
  • 588,226
  • 146
  • 1,060
  • 1,140