Skip to content

Commit c44dc8c

Browse files
committed
[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
1 parent 3586ef9 commit c44dc8c

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

src/helpers/format/format.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -800,7 +800,7 @@ function _createLargeNumberFormat<T extends InternalFormat>(
800800
magnitude: number,
801801
postFix: string
802802
): T {
803-
if (format.type !== "number") {
803+
if (format.type !== "number" || format.scientific) {
804804
return format;
805805
}
806806

tests/functions/module_custom.test.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Model } from "../../src";
22
import { setCellContent, setCellFormat, setFormat } from "../test_helpers/commands_helpers";
3-
import { getCellContent, getCellError } from "../test_helpers/getters_helpers";
3+
import { getCellContent, getCellError, getEvaluatedCell } from "../test_helpers/getters_helpers";
44
import { evaluateCellText } from "../test_helpers/helpers";
55

66
describe("FORMAT.LARGE.NUMBER formula", () => {
@@ -171,6 +171,17 @@ describe("FORMAT.LARGE.NUMBER formula", () => {
171171
expect(getCellContent(model, "A2")).toBe("5,000m");
172172
});
173173

174+
test("FORMAT.LARGE.NUMBER does nothing on numbers with scientific format", () => {
175+
const model = new Model();
176+
setCellContent(model, "A1", "100000");
177+
setFormat(model, "A1", "0e");
178+
setCellContent(model, "A2", "=FORMAT.LARGE.NUMBER(A1)");
179+
expect(getCellContent(model, "A2")).toBe("1e+05");
180+
181+
setFormat(model, "A1", "0;0e;-0e;@[$Hello]");
182+
expect(getEvaluatedCell(model, "A2").format).toBe("0,[$k];0e;-0e;@[$Hello]");
183+
});
184+
174185
test("Percentage in decimal part is preserved by FORMAT.LARGE.NUMBER", () => {
175186
const model = new Model();
176187
setCellContent(model, "A1", "100000");

0 commit comments

Comments
 (0)