name:
src/main/js/formulas/math/EVEN.ts
-rw-r--r--
904
1import { SheetColumnRowKey } from "../../models/common/SheetColumnRowKey";
2import { Complex } from "../../models/common/Types";
3import { Converters } from "../../utils/Converters";
4import { AbstractFormula } from "../AbstractFormula";
5import { FormulaName } from "../FormulaName";
6
7export class EVEN extends AbstractFormula {
8 static SELF: EVEN = new EVEN();
9 NAME = FormulaName.EVEN;
10
11 internal(origin: SheetColumnRowKey, ...values: Array<Complex>) {
12 AbstractFormula.checkLength(values.length, 1, this.NAME);
13 const value = Converters.toNumber(Converters.first(this.collateralLookup(origin, values[0])));
14 let rounded;
15 if (value < 0) {
16 rounded = Math.floor(value);
17 if (rounded % 2 != 0) {
18 return rounded - 1.0;
19 }
20 } else {
21 rounded = Math.ceil(value);
22 if (rounded % 2 != 0) {
23 return rounded + 1.0;
24 }
25 }
26 return rounded;
27 }
28}