diff --git a/src/helpers/format/format.ts b/src/helpers/format/format.ts index 65e31864fe..4fc2d12f23 100644 --- a/src/helpers/format/format.ts +++ b/src/helpers/format/format.ts @@ -813,7 +813,7 @@ function _createLargeNumberFormat( 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]); diff --git a/tests/formats/format_helpers.test.ts b/tests/formats/format_helpers.test.ts index e71251af14..f1041dff99 100644 --- a/tests/formats/format_helpers.test.ts +++ b/tests/formats/format_helpers.test.ts @@ -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(" - ; - ; - ; - "); }); }); diff --git a/tests/formats/formatting_plugin.test.ts b/tests/formats/formatting_plugin.test.ts index a4ab32fe15..a493f3f294 100644 --- a/tests/formats/formatting_plugin.test.ts +++ b/tests/formats/formatting_plugin.test.ts @@ -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", () => { diff --git a/tests/functions/module_custom.test.ts b/tests/functions/module_custom.test.ts index 871472939f..cc6d0e3be3 100644 --- a/tests/functions/module_custom.test.ts +++ b/tests/functions/module_custom.test.ts @@ -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", () => { @@ -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(" - ; - ; - ; - "); + }); });