-
{{ formatNumber(totalData.Power.v, totalData.Power.d) }}
+
+ {{ $n(totalData.Power.v, 'decimal', {
+ minimumFractionDigits: totalData.Power.d,
+ maximumFractionDigits: totalData.Power.d
+ })}}
{{ totalData.Power.u }}
@@ -35,15 +47,11 @@
\ No newline at end of file
diff --git a/webapp/src/locales/index.ts b/webapp/src/locales/index.ts
index cf15b273..64104daf 100644
--- a/webapp/src/locales/index.ts
+++ b/webapp/src/locales/index.ts
@@ -57,4 +57,49 @@ export const dateTimeFormats: I18nOptions["datetimeFormats"] = {
}
};
+export const numberFormats: I18nOptions["numberFormats"] = {
+ [Locales.EN]: {
+ decimal: {
+ style: 'decimal',
+ },
+ decimalNoDigits: {
+ style: 'decimal', minimumFractionDigits: 0, maximumFractionDigits: 0
+ },
+ decimalTwoDigits: {
+ style: 'decimal', minimumFractionDigits: 2, maximumFractionDigits: 2
+ },
+ percent: {
+ style: 'percent',
+ },
+ },
+ [Locales.DE]: {
+ decimal: {
+ style: 'decimal',
+ },
+ decimalNoDigits: {
+ style: 'decimal', minimumFractionDigits: 0, maximumFractionDigits: 0
+ },
+ decimalTwoDigits: {
+ style: 'decimal', minimumFractionDigits: 2, maximumFractionDigits: 2
+ },
+ percent: {
+ style: 'percent',
+ },
+ },
+ [Locales.FR]: {
+ decimal: {
+ style: 'decimal',
+ },
+ decimalNoDigits: {
+ style: 'decimal', minimumFractionDigits: 0, maximumFractionDigits: 0
+ },
+ decimalTwoDigits: {
+ style: 'decimal', minimumFractionDigits: 2, maximumFractionDigits: 2
+ },
+ percent: {
+ style: 'percent',
+ },
+ },
+};
+
export const defaultLocale = Locales.EN;
\ No newline at end of file
diff --git a/webapp/src/main.ts b/webapp/src/main.ts
index c4e6c3a3..8424370b 100644
--- a/webapp/src/main.ts
+++ b/webapp/src/main.ts
@@ -2,7 +2,7 @@ import mitt from 'mitt'
import { createApp } from 'vue'
import { createI18n } from 'vue-i18n'
import App from './App.vue'
-import { defaultLocale, messages, dateTimeFormats } from './locales'
+import { defaultLocale, messages, dateTimeFormats, numberFormats } from './locales'
import { tooltip } from './plugins/bootstrap'
import router from './router'
@@ -23,6 +23,7 @@ const i18n = createI18n({
fallbackLocale: defaultLocale,
messages,
datetimeFormats: dateTimeFormats,
+ numberFormats: numberFormats
})
app.use(router)
diff --git a/webapp/src/utils/index.ts b/webapp/src/utils/index.ts
index 2273bacd..3f33d6e2 100644
--- a/webapp/src/utils/index.ts
+++ b/webapp/src/utils/index.ts
@@ -1,10 +1,8 @@
import { isLoggedIn, login, logout } from './authentication';
-import { formatNumber } from './number';
import { timestampToString } from './time';
export {
timestampToString,
- formatNumber,
login,
logout,
isLoggedIn,
@@ -12,7 +10,6 @@ export {
export default {
timestampToString,
- formatNumber,
login,
logout,
isLoggedIn,
diff --git a/webapp/src/utils/number.ts b/webapp/src/utils/number.ts
deleted file mode 100644
index bcd76125..00000000
--- a/webapp/src/utils/number.ts
+++ /dev/null
@@ -1,5 +0,0 @@
-export const formatNumber = (num: number, digits: number): string => {
- return new Intl.NumberFormat(
- undefined, { minimumFractionDigits: digits, maximumFractionDigits: digits }
- ).format(num);
-}
\ No newline at end of file
diff --git a/webapp/src/views/HomeView.vue b/webapp/src/views/HomeView.vue
index 398ee1a3..9ec6859d 100644
--- a/webapp/src/views/HomeView.vue
+++ b/webapp/src/views/HomeView.vue
@@ -41,8 +41,8 @@
{{ $t('home.DataAge') }} {{ $t('home.Seconds', {'val': inverter.data_age }) }}
@@ -320,7 +320,6 @@ import type { EventlogItems } from '@/types/EventlogStatus';
import type { LimitConfig } from '@/types/LimitConfig';
import type { LimitStatus } from '@/types/LimitStatus';
import type { Inverter, LiveData } from '@/types/LiveDataStatus';
-import { formatNumber } from '@/utils';
import { authHeader, authUrl, handleResponse, isLoggedIn } from '@/utils/authentication';
import * as bootstrap from 'bootstrap';
import {
@@ -439,19 +438,20 @@ export default defineComponent({
computed: {
currentLimitAbsolute(): string {
if (this.currentLimitList.max_power > 0) {
- return formatNumber(this.currentLimitList.limit_relative * this.currentLimitList.max_power / 100, 2);
+ return this.$n(this.currentLimitList.limit_relative * this.currentLimitList.max_power / 100,
+ 'decimalTwoDigits');
}
return "0";
},
currentLimitRelative(): string {
- return formatNumber(this.currentLimitList.limit_relative, 2);
+ return this.$n(this.currentLimitList.limit_relative,
+ 'decimalTwoDigits');
},
inverterData(): Inverter[] {
return this.liveData.inverters;
}
},
methods: {
- formatNumber,
isLoggedIn,
getInitialData() {
this.dataLoading = true;