spreadsheet
typeScript/javascript spreadsheet parser, with formulas.
git clone https://git.vogt.world/spreadsheet.git
Log | Files | README.md
← Commit log
commit
message
Formulas.INT written and tested.
author
Ben Vogt <[email protected]>
date
2017-02-02 03:22:57
stats
2 file(s) changed, 31 insertions(+), 0 deletions(-)
files
src/RawFormulas/RawFormulas.ts
tests/FormulasTest.ts
 1diff --git a/src/RawFormulas/RawFormulas.ts b/src/RawFormulas/RawFormulas.ts
 2index 4647bb5..7b879d6 100644
 3--- a/src/RawFormulas/RawFormulas.ts
 4+++ b/src/RawFormulas/RawFormulas.ts
 5@@ -194,7 +194,19 @@ var __COMPLEX = {
 6 var FISHER = Formula["FISHER"];
 7 var FISHERINV = Formula["FISHERINV"];
 8 var IF = Formula["IF"];
 9-var INT = Formula["INT"];
10+
11+/**
12+ * Rounds a number down to the nearest integer that is less than or equal to it.
13+ * @param values[0] The value to round down to the nearest integer.
14+ * @returns {number} Rounded number
15+ * @constructor
16+ */
17+var INT = function (...values) : number {
18+  checkArgumentsLength(values, 1);
19+  var x = firstValueAsNumber(values[0]);
20+  return Math.floor(x);
21+};
22+
23 var ISEVEN = Formula["ISEVEN"];
24 var ISODD = Formula["ISODD"];
25 var LN = Formula["LN"];
26diff --git a/tests/FormulasTest.ts b/tests/FormulasTest.ts
27index 7858926..b41400e 100644
28--- a/tests/FormulasTest.ts
29+++ b/tests/FormulasTest.ts
30@@ -575,7 +575,25 @@ assertEquals(FISHERINV(0.962), 0.7451676440945232);
31 
32 assertEquals(IF("m" == "m", "hit", "miss"), 'hit');
33 
34+
35+// Test INT
36 assertEquals(INT(99.33), 99);
37+assertEquals(INT(99.99), 99);
38+assertEquals(INT(true), 1);
39+assertEquals(INT(false), 0);
40+assertEquals(INT(""), 0);
41+assertEquals(INT([1.1, "str"]), 1);
42+catchAndAssertEquals(function() {
43+  INT(100, 10);
44+}, ERRORS.NA_ERROR);
45+catchAndAssertEquals(function() {
46+  INT();
47+}, ERRORS.NA_ERROR);
48+catchAndAssertEquals(function() {
49+  INT("str");
50+}, ERRORS.VALUE_ERROR);
51+
52+
53 
54 assertEquals(ISEVEN(4), true);
55