|
|
|
|
|
|
|
|
* properly the result is <b>#VALUE!</b> error. Blank string converts to zero. |
|
|
* properly the result is <b>#VALUE!</b> error. Blank string converts to zero. |
|
|
* |
|
|
* |
|
|
* @author Josh Micich |
|
|
* @author Josh Micich |
|
|
|
|
|
* @author Cédric Walter |
|
|
*/ |
|
|
*/ |
|
|
public final class Value extends Fixed1ArgFunction { |
|
|
public final class Value extends Fixed1ArgFunction { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
boolean foundCurrency = false; |
|
|
boolean foundCurrency = false; |
|
|
boolean foundUnaryPlus = false; |
|
|
boolean foundUnaryPlus = false; |
|
|
boolean foundUnaryMinus = false; |
|
|
boolean foundUnaryMinus = false; |
|
|
|
|
|
boolean foundPercentage = false; |
|
|
|
|
|
|
|
|
int len = strText.length(); |
|
|
int len = strText.length(); |
|
|
int i; |
|
|
int i; |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
switch (ch) { |
|
|
switch (ch) { |
|
|
case ' ': |
|
|
case ' ': |
|
|
String remainingText = strText.substring(i); |
|
|
|
|
|
if (remainingText.trim().length() > 0) { |
|
|
|
|
|
|
|
|
String remainingTextTrimmed = strText.substring(i).trim(); |
|
|
|
|
|
// support for value[space]% |
|
|
|
|
|
if (remainingTextTrimmed.equals("%")) { |
|
|
|
|
|
foundPercentage= true; |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
if (remainingTextTrimmed.length() > 0) { |
|
|
// intervening spaces not allowed once the digits start |
|
|
// intervening spaces not allowed once the digits start |
|
|
return null; |
|
|
return null; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
sb.append(strText.substring(i)); |
|
|
sb.append(strText.substring(i)); |
|
|
i = len; |
|
|
i = len; |
|
|
break; |
|
|
break; |
|
|
|
|
|
case '%': |
|
|
|
|
|
foundPercentage = true; |
|
|
|
|
|
break; |
|
|
default: |
|
|
default: |
|
|
// all other characters are illegal |
|
|
// all other characters are illegal |
|
|
return null; |
|
|
return null; |
|
|
|
|
|
|
|
|
// still a problem parsing the number - probably out of range |
|
|
// still a problem parsing the number - probably out of range |
|
|
return null; |
|
|
return null; |
|
|
} |
|
|
} |
|
|
return new Double(foundUnaryMinus ? -d : d); |
|
|
|
|
|
|
|
|
Double result = new Double(foundUnaryMinus ? -d : d); |
|
|
|
|
|
return foundPercentage ? result /100 : result; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |