Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

in ms excel, 100>"23" , "100">"23" will be converted to Number to compare, hope poi do it the same #5

Open
wants to merge 2 commits into
base: trunk
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Licensed to the Apache Software Foundation (ASF) under one or more
*/
public abstract class RelationalOperationEval extends Fixed2ArgFunction {

/**
/**
* Converts a standard compare result (-1, 0, 1) to <code>true</code> or <code>false</code>
* according to subclass' comparison type.
*/
Expand All @@ -45,7 +45,7 @@ public abstract class RelationalOperationEval extends Fixed2ArgFunction {
* Bool.TRUE > Bool.FALSE
* Bool.FALSE == Blank
*
* Strings are never converted to numbers or booleans
* Strings can converted to numbers or booleans to compare
* String > any number. ALWAYS
* Non-empty String > Blank
* Empty String == Blank
Expand Down Expand Up @@ -94,6 +94,15 @@ private static int doCompare(ValueEval va, ValueEval vb) {
if (vb instanceof BoolEval) {
return -1;
}

try {
Double nA = OperandResolver.coerceValueToDouble(va);
Double nB = OperandResolver.coerceValueToDouble(vb);
return NumberComparer.compare(nA, nB);
} catch (Exception e) {
//
}

if (va instanceof StringEval) {
if (vb instanceof StringEval) {
StringEval sA = (StringEval) va;
Expand All @@ -105,13 +114,6 @@ private static int doCompare(ValueEval va, ValueEval vb) {
if (vb instanceof StringEval) {
return -1;
}
if (va instanceof NumberEval) {
if (vb instanceof NumberEval) {
NumberEval nA = (NumberEval) va;
NumberEval nB = (NumberEval) vb;
return NumberComparer.compare(nA.getNumberValue(), nB.getNumberValue());
}
}
throw new IllegalArgumentException("Bad operand types (" + va.getClass().getName() + "), ("
+ vb.getClass().getName() + ")");
}
Expand Down