diff options
author | Cédric Walter <cedricwalter@apache.org> | 2013-08-16 17:15:47 +0000 |
---|---|---|
committer | Cédric Walter <cedricwalter@apache.org> | 2013-08-16 17:15:47 +0000 |
commit | 1b795e34f794642ebbda58cc256515844146b2bd (patch) | |
tree | 204c280cd179d26d5b9d50a5cfda91adce0846e9 /src/java/org/apache | |
parent | 04e0efdbd5c682411c7c8ced705341223366f582 (diff) | |
download | poi-1b795e34f794642ebbda58cc256515844146b2bd.tar.gz poi-1b795e34f794642ebbda58cc256515844146b2bd.zip |
Bug 54723: Support for percentage in VALUE() function
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1514799 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache')
-rw-r--r-- | src/java/org/apache/poi/ss/formula/functions/Value.java | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/src/java/org/apache/poi/ss/formula/functions/Value.java b/src/java/org/apache/poi/ss/formula/functions/Value.java index 811db9c14c..d8bc377f97 100644 --- a/src/java/org/apache/poi/ss/formula/functions/Value.java +++ b/src/java/org/apache/poi/ss/formula/functions/Value.java @@ -34,6 +34,7 @@ import org.apache.poi.ss.formula.eval.ValueEval; * properly the result is <b>#VALUE!</b> error. Blank string converts to zero. * * @author Josh Micich + * @author Cédric Walter */ public final class Value extends Fixed1ArgFunction { @@ -65,6 +66,7 @@ public final class Value extends Fixed1ArgFunction { boolean foundCurrency = false; boolean foundUnaryPlus = false; boolean foundUnaryMinus = false; + boolean foundPercentage = false; int len = strText.length(); int i; @@ -123,8 +125,13 @@ public final class Value extends Fixed1ArgFunction { } switch (ch) { 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 return null; } @@ -162,6 +169,9 @@ public final class Value extends Fixed1ArgFunction { sb.append(strText.substring(i)); i = len; break; + case '%': + foundPercentage = true; + break; default: // all other characters are illegal return null; @@ -179,6 +189,7 @@ public final class Value extends Fixed1ArgFunction { // still a problem parsing the number - probably out of range return null; } - return new Double(foundUnaryMinus ? -d : d); + Double result = new Double(foundUnaryMinus ? -d : d); + return foundPercentage ? result /100 : result; } } |