From bb22b0f5bcbbba5983fbe08b11740253f99326dd Mon Sep 17 00:00:00 2001 From: Michael Geers Date: Fri, 18 Apr 2025 08:56:56 +0200 Subject: [PATCH] UI: no digits on 0W (#20682) --- assets/js/mixins/formatter.test.js | 8 ++++---- assets/js/mixins/formatter.ts | 7 ++++++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/assets/js/mixins/formatter.test.js b/assets/js/mixins/formatter.test.js index 67f799bfe..d33b6fb89 100644 --- a/assets/js/mixins/formatter.test.js +++ b/assets/js/mixins/formatter.test.js @@ -18,7 +18,7 @@ describe("fmtW", () => { expect(fmt.fmtW(1200000, POWER_UNIT.MW)).eq("1,2 MW"); expect(fmt.fmtW(0, POWER_UNIT.KW)).eq("0,0 kW"); expect(fmt.fmtW(1200000, POWER_UNIT.KW)).eq("1.200,0 kW"); - expect(fmt.fmtW(0, POWER_UNIT.W)).eq("0,0 W"); + expect(fmt.fmtW(0, POWER_UNIT.W)).eq("0 W"); expect(fmt.fmtW(1200000, POWER_UNIT.W)).eq("1.200.000 W"); }); test("should format without units", () => { @@ -28,7 +28,7 @@ describe("fmtW", () => { expect(fmt.fmtW(1200000, POWER_UNIT.MW, false)).eq("1,2"); expect(fmt.fmtW(0, POWER_UNIT.KW, false)).eq("0,0"); expect(fmt.fmtW(1200000, POWER_UNIT.KW, false)).eq("1.200,0"); - expect(fmt.fmtW(0, POWER_UNIT.W, false)).eq("0,0"); + expect(fmt.fmtW(0, POWER_UNIT.W, false)).eq("0"); expect(fmt.fmtW(1200000, POWER_UNIT.W, false)).eq("1.200.000"); }); test("should format a given number of digits", () => { @@ -55,7 +55,7 @@ describe("fmtWh", () => { expect(fmt.fmtWh(1200000, POWER_UNIT.MW)).eq("1,2 MWh"); expect(fmt.fmtWh(0, POWER_UNIT.KW)).eq("0,0 kWh"); expect(fmt.fmtWh(1200000, POWER_UNIT.KW)).eq("1.200,0 kWh"); - expect(fmt.fmtWh(0, POWER_UNIT.W)).eq("0,0 Wh"); + expect(fmt.fmtWh(0, POWER_UNIT.W)).eq("0 Wh"); expect(fmt.fmtWh(1200000, POWER_UNIT.W)).eq("1.200.000 Wh"); }); test("should format without units", () => { @@ -65,7 +65,7 @@ describe("fmtWh", () => { expect(fmt.fmtWh(1200000, POWER_UNIT.MW, false)).eq("1,2"); expect(fmt.fmtWh(0, POWER_UNIT.KW, false)).eq("0,0"); expect(fmt.fmtWh(1200000, POWER_UNIT.KW, false)).eq("1.200,0"); - expect(fmt.fmtWh(0, POWER_UNIT.W, false)).eq("0,0"); + expect(fmt.fmtWh(0, POWER_UNIT.W, false)).eq("0"); expect(fmt.fmtWh(1200000, POWER_UNIT.W, false)).eq("1.200.000"); }); test("should format a given number of digits", () => { diff --git a/assets/js/mixins/formatter.ts b/assets/js/mixins/formatter.ts index 6581c2f6f..3a5cd98ea 100644 --- a/assets/js/mixins/formatter.ts +++ b/assets/js/mixins/formatter.ts @@ -57,7 +57,12 @@ export default defineComponent({ value = watt / 1_000_000; } if (d === undefined) { - d = POWER_UNIT.KW === unit || POWER_UNIT.MW === unit || 0 === watt ? 1 : 0; + d = + POWER_UNIT.KW === unit || + POWER_UNIT.MW === unit || + (POWER_UNIT.W !== unit && 0 === watt) + ? 1 + : 0; } return `${new Intl.NumberFormat(this.$i18n?.locale, { style: "decimal",