f7
f7 is a spreadsheet formula execution library
git clone https://git.vogt.world/f7.git
Log | Files | README.md | LICENSE.md
← All files
name: src/main/js/formulas/math/ROUNDDOWN.ts
-rw-r--r--
1362
 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 ROUNDDOWN extends AbstractFormula {
 8  static SELF: ROUNDDOWN = new ROUNDDOWN();
 9  NAME = FormulaName.ROUNDDOWN;
10
11  internal(origin: SheetColumnRowKey, ...values: Array<Complex>) {
12    AbstractFormula.checkLengthBetween(values.length, 1, 2, this.NAME);
13    const value = Converters.first(this.collateralLookup(origin, values[0]));
14    let placesRaw;
15    if (values.length === 1) {
16      placesRaw = 0.0;
17    } else {
18      placesRaw = Converters.toNumber(Converters.first(this.collateralLookup(origin, values[1])));
19    }
20    const n = Converters.toNumber(value);
21    const places = placesRaw > 0 ? Math.floor(placesRaw) : Math.ceil(placesRaw);
22    if (n < 0) {
23      if (places < 0) {
24        return Number(Math.ceil(parseFloat(n + "e-" + places * -1)) + "e" + places * -1);
25      }
26      return Number(Math.ceil(parseFloat(n + "e" + places)) + "e-" + places);
27    }
28    if (places < 0) {
29      return Number(Math.floor(parseFloat(n + "e-" + places * -1)) + "e" + places * -1);
30    }
31    return Number(Math.floor(parseFloat(n + "e" + places)) + "e-" + places);
32  }
33}