Hello JavaHopper and to all you other people.
I think, I found the solution.
My setup:
- NetBeans 8.2 (Build 201609300101)
- Java EE6
- Apache Tomcat 8.0.27.0
and
- tomcat-jasper-8.0.0-rc1-sources.jar
from this page: http://www.java2s.com/Code/Jar/t/Downloadtomcatjasper800rc1sourcesjar.htm
for debugging.
As you said, if both operands are "null" then you get 0 as a result.
If I let it debug, it will come to the point, where it call a method named:
public static final Number divide(final Object obj0, final Object obj1)
which can be found here:
org.apache.el.lang.ELArithmetic.divide(obj0, obj1)
and here is the complete method:
public static final Number divide(final Object obj0, final Object obj1) {
if (obj0 == null && obj1 == null) {
return ZERO;
}
final ELArithmetic delegate;
if (BIGDECIMAL.matches(obj0, obj1))
delegate = BIGDECIMAL;
else if (BIGINTEGER.matches(obj0, obj1))
delegate = BIGDECIMAL;
else
delegate = DOUBLE;
Number num0 = delegate.coerce(obj0);
Number num1 = delegate.coerce(obj1);
return delegate.divide(num0, num1);
}
As you can see at the beginning of the method their is a check, if both operands are null.
If yes you get 0 (ZERO) back and will show as a String on your JSP site for example.
So it has not quite to do with a mathematical rule.
Hope, this helps a little bit.
Best regards
rikku47
PS:
In short you can just call:
org.apache.el.lang.ELArithmetic.divide(null, null);