From c44dc8c08f4c19f34af6c29820339d1558827ee8 Mon Sep 17 00:00:00 2001 From: "Adrien Minne (adrm)" Date: Thu, 26 Mar 2026 10:07:36 +0100 Subject: [PATCH] [FIX] format: don't humanize scientific format The methods trying to humanize a format (in charts, and in `FORMAT.LARGE.NUMBER`) were displaying strange results when used with scientific formats (eg. `0ke+4` instead of either `50k` or `5e+4`). Task: 6068353 --- src/helpers/format/format.ts | 2 +- tests/functions/module_custom.test.ts | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/helpers/format/format.ts b/src/helpers/format/format.ts index 448752e9d8..4c57770c96 100644 --- a/src/helpers/format/format.ts +++ b/src/helpers/format/format.ts @@ -800,7 +800,7 @@ function _createLargeNumberFormat( magnitude: number, postFix: string ): T { - if (format.type !== "number") { + if (format.type !== "number" || format.scientific) { return format; } diff --git a/tests/functions/module_custom.test.ts b/tests/functions/module_custom.test.ts index 871472939f..906753d4a9 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", () => { @@ -171,6 +171,17 @@ describe("FORMAT.LARGE.NUMBER formula", () => { expect(getCellContent(model, "A2")).toBe("5,000m"); }); + test("FORMAT.LARGE.NUMBER does nothing on numbers with scientific format", () => { + const model = new Model(); + setCellContent(model, "A1", "100000"); + setFormat(model, "A1", "0e"); + setCellContent(model, "A2", "=FORMAT.LARGE.NUMBER(A1)"); + expect(getCellContent(model, "A2")).toBe("1e+05"); + + setFormat(model, "A1", "0;0e;-0e;@[$Hello]"); + expect(getEvaluatedCell(model, "A2").format).toBe("0,[$k];0e;-0e;@[$Hello]"); + }); + test("Percentage in decimal part is preserved by FORMAT.LARGE.NUMBER", () => { const model = new Model(); setCellContent(model, "A1", "100000");