Author: cedricwalter
Date: Fri Aug 16 17:15:47 2013
New Revision: 1514799
URL: http://svn.apache.org/r1514799
Log:
Bug 54723: Support for percentage in VALUE() function
Modified:
poi/trunk/src/java/org/apache/poi/ss/formula/functions/Value.java
poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestValue.java
Modified: poi/trunk/src/java/org/apache/poi/ss/formula/functions/Value.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/formula/functions/Value.java?rev=1514799&r1=1514798&r2=1514799&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/formula/functions/Value.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/formula/functions/Value.java Fri Aug
16 17:15:47 2013
@@ -34,6 +34,7 @@ import org.apache.poi.ss.formula.eval.Va
* 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 Fixed1A
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 Fixed1A
}
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 Fixed1A
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 Fixed1A
// 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;
}
}
Modified:
poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestValue.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestValue.java?rev=1514799&r1=1514798&r2=1514799&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestValue.java
(original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestValue.java
Fri Aug 16 17:15:47 2013
@@ -28,6 +28,7 @@ import org.apache.poi.ss.formula.eval.Va
* Tests for {@link Value}
*
* @author Josh Micich
+ * @author Cédric Walter
*/
public final class TestValue extends TestCase {
@@ -71,6 +72,8 @@ public final class TestValue extends Tes
confirmValue("1,000e2", 100000);
confirmValue("$10e2", 1000);
confirmValue("$1,000e2", 100000);
+ confirmValue("30%", 0.3);
+ confirmValue("30 %", 0.3);
}
public void testErrors() {
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]