commit
message
[UNARY_PERCENT] formula added and tested
author
Ben Vogt <[email protected]>
date
2017-07-08 02:34:26
stats
8 file(s) changed,
56 insertions(+),
5 deletions(-)
files
DOCS.md
TODO.md
dist/Formulas/AllFormulas.js
dist/Formulas/Math.js
src/Formulas/AllFormulas.ts
src/Formulas/Math.ts
tests/Formulas/MathTest.ts
tests/SheetFormulaTest.ts
1diff --git a/DOCS.md b/DOCS.md
2index 39503f2..99857f8 100644
3--- a/DOCS.md
4+++ b/DOCS.md
5@@ -1365,6 +1365,15 @@
6 @returns {number}
7 @constructor
8 ```
9+
10+### PERCENT
11+
12+```
13+ Returns a value as a percentage where 100 is 1.0, and 0 is 0.
14+@param value - To convert.
15+@returns {number}
16+@constructor
17+```
18 ## Range
19
20
21diff --git a/TODO.md b/TODO.md
22index 472237c..ff4a55a 100644
23--- a/TODO.md
24+++ b/TODO.md
25@@ -51,7 +51,6 @@ For example 64 tbs to a qt.
26 * MULTINOMIAL
27 * SERIESSUM
28 * SUBTOTAL
29-* UNARY_PERCENT
30 * TO_DATE - Contingent upon cells having display formats derived from type-hierarchy
31 * TO_DOLLARS - Contingent upon cells having display formats derived from type-hierarchy
32 * TO_PERCENT - Contingent upon cells having display formats derived from type-hierarchy
33diff --git a/dist/Formulas/AllFormulas.js b/dist/Formulas/AllFormulas.js
34index 8511065..a115e5b 100644
35--- a/dist/Formulas/AllFormulas.js
36+++ b/dist/Formulas/AllFormulas.js
37@@ -73,6 +73,7 @@ exports.UPLUS = Math_1.UPLUS;
38 exports.UMINUS = Math_1.UMINUS;
39 exports.MROUND = Math_1.MROUND;
40 exports.FACTDOUBLE = Math_1.FACTDOUBLE;
41+exports.UNARY_PERCENT = Math_1.UNARY_PERCENT;
42 var Range_1 = require("./Range");
43 exports.FREQUENCY = Range_1.FREQUENCY;
44 exports.GROWTH = Range_1.GROWTH;
45diff --git a/dist/Formulas/Math.js b/dist/Formulas/Math.js
46index 9fddc50..228f8ac 100644
47--- a/dist/Formulas/Math.js
48+++ b/dist/Formulas/Math.js
49@@ -1331,3 +1331,14 @@ var FACTDOUBLE = function (value) {
50 }
51 };
52 exports.FACTDOUBLE = FACTDOUBLE;
53+/**
54+ * Returns a value as a percentage where 100 is 1.0, and 0 is 0.
55+ * @param value - To convert.
56+ * @returns {number}
57+ * @constructor
58+ */
59+var UNARY_PERCENT = function (value) {
60+ ArgsChecker_1.ArgsChecker.checkLength(arguments, 1, "UNARY_PERCENT");
61+ return TypeConverter_1.TypeConverter.firstValueAsNumber(value) / 100;
62+};
63+exports.UNARY_PERCENT = UNARY_PERCENT;
64diff --git a/src/Formulas/AllFormulas.ts b/src/Formulas/AllFormulas.ts
65index ebe2932..6749708 100644
66--- a/src/Formulas/AllFormulas.ts
67+++ b/src/Formulas/AllFormulas.ts
68@@ -70,7 +70,8 @@ import {
69 UPLUS,
70 UMINUS,
71 MROUND,
72- FACTDOUBLE
73+ FACTDOUBLE,
74+ UNARY_PERCENT
75 } from "./Math";
76 import {
77 FREQUENCY,
78@@ -416,5 +417,6 @@ export {
79 GEOMEAN,
80 HARMEAN,
81 CONFIDENCE,
82- N
83+ N,
84+ UNARY_PERCENT
85 }
86\ No newline at end of file
87diff --git a/src/Formulas/Math.ts b/src/Formulas/Math.ts
88index c00ed74..f9590af 100644
89--- a/src/Formulas/Math.ts
90+++ b/src/Formulas/Math.ts
91@@ -1341,6 +1341,17 @@ var FACTDOUBLE = function (value) {
92 }
93 };
94
95+/**
96+ * Returns a value as a percentage where 100 is 1.0, and 0 is 0.
97+ * @param value - To convert.
98+ * @returns {number}
99+ * @constructor
100+ */
101+var UNARY_PERCENT = function (value) {
102+ ArgsChecker.checkLength(arguments, 1, "UNARY_PERCENT");
103+ return TypeConverter.firstValueAsNumber(value) / 100;
104+};
105+
106 export {
107 ABS,
108 ACOS,
109@@ -1413,5 +1424,6 @@ export {
110 UPLUS,
111 UMINUS,
112 MROUND,
113- FACTDOUBLE
114+ FACTDOUBLE,
115+ UNARY_PERCENT
116 }
117\ No newline at end of file
118diff --git a/tests/Formulas/MathTest.ts b/tests/Formulas/MathTest.ts
119index ab1a153..74f4eb4 100644
120--- a/tests/Formulas/MathTest.ts
121+++ b/tests/Formulas/MathTest.ts
122@@ -70,7 +70,8 @@ import {
123 UPLUS,
124 UMINUS,
125 MROUND,
126- FACTDOUBLE
127+ FACTDOUBLE,
128+ UNARY_PERCENT
129 } from "../../src/Formulas/Math";
130 import * as ERRORS from "../../src/Errors";
131 import {
132@@ -1490,4 +1491,14 @@ test("SIGN", function(){
133 catchAndAssertEquals(function() {
134 SIGN.apply(this, [3, 2]);
135 }, ERRORS.NA_ERROR);
136+});
137+
138+
139+test("UNARY_PERCENT", function(){
140+ assertEquals(UNARY_PERCENT(100), 1);
141+ assertEquals(UNARY_PERCENT(2), 0.02);
142+ assertEquals(UNARY_PERCENT(0), 0);
143+ catchAndAssertEquals(function() {
144+ UNARY_PERCENT.apply(this, []);
145+ }, ERRORS.NA_ERROR);
146 });
147\ No newline at end of file
148diff --git a/tests/SheetFormulaTest.ts b/tests/SheetFormulaTest.ts
149index 636d9d5..c249510 100644
150--- a/tests/SheetFormulaTest.ts
151+++ b/tests/SheetFormulaTest.ts
152@@ -813,6 +813,10 @@ test("Sheet N", function(){
153 assertFormulaEquals('=N("10")', 10);
154 });
155
156+test("Sheet UNARY_PERCENT", function(){
157+ assertFormulaEquals('=UNARY_PERCENT(10)', 0.1);
158+});
159+
160 test("Sheet *", function(){
161 assertFormulaEquals('= 10 * 10', 100);
162 assertFormulaEquals('= 10 * 0', 0);