([
"clear-night",
@@ -106,15 +106,19 @@ export const getWind = (
speed: string,
bearing: string
): string => {
+ const speedText = `${formatNumber(speed, hass!.language)} ${getWeatherUnit(
+ hass!,
+ "wind_speed"
+ )}`;
if (bearing !== null) {
const cardinalDirection = getWindBearing(bearing);
- return `${speed} ${getWeatherUnit(hass!, "wind_speed")} (${
+ return `${speedText} (${
hass.localize(
`ui.card.weather.cardinal_direction.${cardinalDirection.toLowerCase()}`
) || cardinalDirection
})`;
}
- return `${speed} ${getWeatherUnit(hass!, "wind_speed")}`;
+ return speedText;
};
export const getWeatherUnit = (
@@ -175,7 +179,8 @@ export const getSecondaryWeatherAttribute = (
`
: hass!.localize(`ui.card.weather.attributes.${attribute}`)}
- ${roundWithOneDecimal(value)} ${getWeatherUnit(hass!, attribute)}
+ ${formatNumber(value, hass!.language, { maximumFractionDigits: 1 })}
+ ${getWeatherUnit(hass!, attribute)}
`;
};
diff --git a/src/dialogs/more-info/controls/more-info-sun.ts b/src/dialogs/more-info/controls/more-info-sun.ts
index 135ee13c53..80fa678ee4 100644
--- a/src/dialogs/more-info/controls/more-info-sun.ts
+++ b/src/dialogs/more-info/controls/more-info-sun.ts
@@ -9,6 +9,7 @@ import {
TemplateResult,
} from "lit-element";
import { formatTime } from "../../../common/datetime/format_time";
+import { formatNumber } from "../../../common/string/format_number";
import "../../../components/ha-relative-time";
import { HomeAssistant } from "../../../types";
@@ -59,7 +60,12 @@ class MoreInfoSun extends LitElement {
${this.hass.localize("ui.dialogs.more_info_control.sun.elevation")}
- ${this.stateObj.attributes.elevation}
+
+ ${formatNumber(
+ this.stateObj.attributes.elevation,
+ this.hass!.language
+ )}
+
`;
}
diff --git a/src/dialogs/more-info/controls/more-info-weather.ts b/src/dialogs/more-info/controls/more-info-weather.ts
index 7e962071a5..4d3c38ca90 100644
--- a/src/dialogs/more-info/controls/more-info-weather.ts
+++ b/src/dialogs/more-info/controls/more-info-weather.ts
@@ -34,6 +34,7 @@ import {
mdiWeatherWindy,
mdiWeatherWindyVariant,
} from "@mdi/js";
+import { formatNumber } from "../../../common/string/format_number";
const weatherIcons = {
"clear-night": mdiWeatherNight,
@@ -88,7 +89,10 @@ class MoreInfoWeather extends LitElement {
${this.hass.localize("ui.card.weather.attributes.temperature")}
- ${this.stateObj.attributes.temperature}
+ ${formatNumber(
+ this.stateObj.attributes.temperature,
+ this.hass!.language
+ )}
${getWeatherUnit(this.hass, "temperature")}
@@ -100,7 +104,10 @@ class MoreInfoWeather extends LitElement {
${this.hass.localize("ui.card.weather.attributes.air_pressure")}
- ${this.stateObj.attributes.pressure}
+ ${formatNumber(
+ this.stateObj.attributes.pressure,
+ this.hass!.language
+ )}
${getWeatherUnit(this.hass, "air_pressure")}
@@ -113,7 +120,13 @@ class MoreInfoWeather extends LitElement {
${this.hass.localize("ui.card.weather.attributes.humidity")}
- ${this.stateObj.attributes.humidity} %
+
+ ${formatNumber(
+ this.stateObj.attributes.humidity,
+ this.hass!.language
+ )}
+ %
+
`
: ""}
@@ -142,7 +155,10 @@ class MoreInfoWeather extends LitElement {
${this.hass.localize("ui.card.weather.attributes.visibility")}
- ${this.stateObj.attributes.visibility}
+ ${formatNumber(
+ this.stateObj.attributes.visibility,
+ this.hass!.language
+ )}
${getWeatherUnit(this.hass, "length")}
@@ -176,13 +192,13 @@ class MoreInfoWeather extends LitElement {
${this.computeDate(item.datetime)}
- ${item.templow}
+ ${formatNumber(item.templow, this.hass!.language)}
${getWeatherUnit(this.hass, "temperature")}
`
: ""}
- ${item.temperature}
+ ${formatNumber(item.temperature, this.hass!.language)}
${getWeatherUnit(this.hass, "temperature")}
diff --git a/src/panels/lovelace/cards/hui-entity-card.ts b/src/panels/lovelace/cards/hui-entity-card.ts
index 3cc2cdaf63..66b071c752 100644
--- a/src/panels/lovelace/cards/hui-entity-card.ts
+++ b/src/panels/lovelace/cards/hui-entity-card.ts
@@ -31,6 +31,7 @@ import {
import { HuiErrorCard } from "./hui-error-card";
import { EntityCardConfig } from "./types";
import { computeCardSize } from "../common/compute-card-size";
+import { formatNumber } from "../../../common/string/format_number";
@customElement("hui-entity-card")
export class HuiEntityCard extends LitElement implements LovelaceCard {
@@ -128,7 +129,7 @@ export class HuiEntityCard extends LitElement implements LovelaceCard {
? stateObj.attributes[this._config.attribute!] ??
this.hass.localize("state.default.unknown")
: stateObj.attributes.unit_of_measurement
- ? stateObj.state
+ ? formatNumber(stateObj.state, this.hass!.language)
: computeStateDisplay(
this.hass.localize,
stateObj,
diff --git a/src/panels/lovelace/cards/hui-gauge-card.ts b/src/panels/lovelace/cards/hui-gauge-card.ts
index 5c14283062..47be53b049 100644
--- a/src/panels/lovelace/cards/hui-gauge-card.ts
+++ b/src/panels/lovelace/cards/hui-gauge-card.ts
@@ -128,6 +128,7 @@ class HuiGaugeCard extends LitElement implements LovelaceCard {
.min=${this._config.min!}
.max=${this._config.max!}
.value=${state}
+ .language=${this.hass!.language}
.label=${this._config!.unit ||
this.hass?.states[this._config!.entity].attributes
.unit_of_measurement ||
diff --git a/src/panels/lovelace/cards/hui-thermostat-card.ts b/src/panels/lovelace/cards/hui-thermostat-card.ts
index 0f7935db30..d78318531f 100644
--- a/src/panels/lovelace/cards/hui-thermostat-card.ts
+++ b/src/panels/lovelace/cards/hui-thermostat-card.ts
@@ -19,6 +19,7 @@ import { UNIT_F } from "../../../common/const";
import { applyThemesOnElement } from "../../../common/dom/apply_themes_on_element";
import { fireEvent } from "../../../common/dom/fire_event";
import { computeStateName } from "../../../common/entity/compute_state_name";
+import { formatNumber } from "../../../common/string/format_number";
import "../../../components/ha-card";
import type { HaCard } from "../../../components/ha-card";
import "../../../components/ha-icon-button";
@@ -141,7 +142,10 @@ export class HuiThermostatCard extends LitElement implements LovelaceCard {
text-anchor="middle"
style="font-size: 13px;"
>
- ${stateObj.attributes.current_temperature}
+ ${formatNumber(
+ stateObj.attributes.current_temperature,
+ this.hass!.language
+ )}
${this.hass.config.unit_system.temperature}
@@ -162,19 +166,34 @@ export class HuiThermostatCard extends LitElement implements LovelaceCard {
: Array.isArray(this._setTemp)
? this._stepSize === 1
? svg`
- ${this._setTemp[0].toFixed()} -
- ${this._setTemp[1].toFixed()}
+ ${formatNumber(this._setTemp[0], this.hass!.language, {
+ maximumFractionDigits: 0,
+ })} -
+ ${formatNumber(this._setTemp[1], this.hass!.language, {
+ maximumFractionDigits: 0,
+ })}
`
: svg`
- ${this._setTemp[0].toFixed(1)} -
- ${this._setTemp[1].toFixed(1)}
+ ${formatNumber(this._setTemp[0], this.hass!.language, {
+ minimumFractionDigits: 1,
+ maximumFractionDigits: 1,
+ })} -
+ ${formatNumber(this._setTemp[1], this.hass!.language, {
+ minimumFractionDigits: 1,
+ maximumFractionDigits: 1,
+ })}
`
: this._stepSize === 1
? svg`
- ${this._setTemp.toFixed()}
+ ${formatNumber(this._setTemp, this.hass!.language, {
+ maximumFractionDigits: 0,
+ })}
`
: svg`
- ${this._setTemp.toFixed(1)}
+ ${formatNumber(this._setTemp, this.hass!.language, {
+ minimumFractionDigits: 1,
+ maximumFractionDigits: 1,
+ })}
`
}
diff --git a/src/panels/lovelace/cards/hui-weather-forecast-card.ts b/src/panels/lovelace/cards/hui-weather-forecast-card.ts
index 336842b4fa..e0425180b9 100644
--- a/src/panels/lovelace/cards/hui-weather-forecast-card.ts
+++ b/src/panels/lovelace/cards/hui-weather-forecast-card.ts
@@ -15,6 +15,7 @@ import { computeStateDisplay } from "../../../common/entity/compute_state_displa
import { computeStateName } from "../../../common/entity/compute_state_name";
import { stateIcon } from "../../../common/entity/state_icon";
import { isValidEntityId } from "../../../common/entity/valid_entity_id";
+import { formatNumber } from "../../../common/string/format_number";
import { debounce } from "../../../common/util/debounce";
import "../../../components/ha-card";
import "../../../components/ha-icon";
@@ -214,9 +215,10 @@ class HuiWeatherForecastCard extends LitElement implements LovelaceCard {
- ${stateObj.attributes.temperature}${getWeatherUnit(this.hass, "temperature")}
+ ${formatNumber(
+ stateObj.attributes.temperature,
+ this.hass!.language
+ )}${getWeatherUnit(this.hass, "temperature")}
${this._config.secondary_info_attribute !== undefined
@@ -241,9 +243,12 @@ class HuiWeatherForecastCard extends LitElement implements LovelaceCard {
stateObj.attributes.wind_bearing
)
: html`
- ${stateObj.attributes[
- this._config.secondary_info_attribute
- ]}
+ ${formatNumber(
+ stateObj.attributes[
+ this._config.secondary_info_attribute
+ ],
+ this.hass!.language
+ )}
${getWeatherUnit(
this.hass,
this._config.secondary_info_attribute
@@ -307,14 +312,20 @@ class HuiWeatherForecastCard extends LitElement implements LovelaceCard {
item.temperature !== null
? html`
- ${item.temperature}°
+ ${formatNumber(
+ item.temperature,
+ this.hass!.language
+ )}°
`
: ""}
${item.templow !== undefined && item.templow !== null
? html`
- ${item.templow}°
+ ${formatNumber(
+ item.templow,
+ this.hass!.language
+ )}°
`
: ""}