Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/helpers/format/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,7 @@ function _createLargeNumberFormat<T extends InternalFormat>(

const lastDigitIndex = newIntegerPart.findLastIndex((token) => token.type === "DIGIT");
if (lastDigitIndex === -1) {
throw new Error("Cannot create a large number format from a format with no digit.");
return format;
}
while (newIntegerPart[lastDigitIndex + 1]?.type === "THOUSANDS_SEPARATOR") {
newIntegerPart = removeIndexesFromArray(newIntegerPart, [lastDigitIndex + 1]);
Expand Down
1 change: 1 addition & 0 deletions tests/formats/format_helpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1091,6 +1091,7 @@ describe("rounding format", () => {
test("Round multi part format", () => {
expect(roundFormat("0.00\\€;$0.#; 0.00 ;@")).toBe("0\\€;$0; 0 ;@");
expect(roundFormat("dd/mm/yyyy;0.#")).toBe("dd/mm/yyyy;0");
expect(roundFormat(" - ; - ; - ; - ")).toBe(" - ; - ; - ; - ");
});
});

Expand Down
4 changes: 4 additions & 0 deletions tests/formats/formatting_plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,10 @@ describe("formatting values (with formatters)", () => {
setFormat(model, "A1", ";;;@");
setDecimal(model, "A1", -1);
expect(getCell(model, "A1")?.format).toBe(";;;@");

setFormat(model, "A1", " - ; - ; - ; - ");
setDecimal(model, "A1", -1);
expect(getCell(model, "A1")?.format).toBe(" - ; - ; - ; - ");
});

test("SET_DECIMAL on scientific format", () => {
Expand Down
10 changes: 9 additions & 1 deletion tests/functions/module_custom.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Model } from "../../src";
import { setCellContent, setCellFormat, setFormat } from "../test_helpers/commands_helpers";
import { getCellContent, getCellError } from "../test_helpers/getters_helpers";
import { getCellContent, getCellError, getEvaluatedCell } from "../test_helpers/getters_helpers";
import { evaluateCellText } from "../test_helpers/helpers";

describe("FORMAT.LARGE.NUMBER formula", () => {
Expand Down Expand Up @@ -178,4 +178,12 @@ describe("FORMAT.LARGE.NUMBER formula", () => {
setCellContent(model, "A2", "=FORMAT.LARGE.NUMBER(A1)");
expect(getCellContent(model, "A2")).toBe("10,000k%");
});

test("FORMAT.LARGE.NUMBER does not crash on format without digits", () => {
const model = new Model();
setCellContent(model, "A1", "100000");
setFormat(model, "A1", " - ; - ; - ; - ");
setCellContent(model, "A2", "=FORMAT.LARGE.NUMBER(A1)");
expect(getEvaluatedCell(model, "A2")?.format).toBe(" - ; - ; - ; - ");
});
});