From 20e856ecfcf9c9af9cc3b21b37c5335d49da3a90 Mon Sep 17 00:00:00 2001 From: Thomas Basler Date: Mon, 31 Oct 2022 15:08:56 +0100 Subject: [PATCH] Use correct locale for number formatting Also moved numberFormat method so separate file --- webapp/src/components/InverterChannelInfo.vue | 7 ++-- .../src/components/LimitSettingsCurrent.vue | 15 +++------ webapp/src/utils/index.ts | 3 ++ webapp/src/utils/number.ts | 5 +++ webapp/src/views/HomeView.vue | 32 +++++++++++-------- 5 files changed, 33 insertions(+), 29 deletions(-) create mode 100644 webapp/src/utils/number.ts diff --git a/webapp/src/components/InverterChannelInfo.vue b/webapp/src/components/InverterChannelInfo.vue index f3af0c6f..025c0817 100644 --- a/webapp/src/components/InverterChannelInfo.vue +++ b/webapp/src/components/InverterChannelInfo.vue @@ -28,6 +28,7 @@ diff --git a/webapp/src/components/LimitSettingsCurrent.vue b/webapp/src/components/LimitSettingsCurrent.vue index fd9c99cd..24ced637 100644 --- a/webapp/src/components/LimitSettingsCurrent.vue +++ b/webapp/src/components/LimitSettingsCurrent.vue @@ -3,7 +3,7 @@ Current Limit - {{ formatNumber(limitData.limit) }}% + {{ formatNumber(limitData.limit, 2) }}% @@ -11,6 +11,7 @@ \ No newline at end of file diff --git a/webapp/src/utils/index.ts b/webapp/src/utils/index.ts index 0db17789..d96d8ac8 100644 --- a/webapp/src/utils/index.ts +++ b/webapp/src/utils/index.ts @@ -1,9 +1,12 @@ import { timestampToString } from './time'; +import { formatNumber } from './number'; export { timestampToString, + formatNumber, }; export default { timestampToString, + formatNumber, } \ No newline at end of file diff --git a/webapp/src/utils/number.ts b/webapp/src/utils/number.ts new file mode 100644 index 00000000..bcd76125 --- /dev/null +++ b/webapp/src/utils/number.ts @@ -0,0 +1,5 @@ +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 5aa37436..651011c0 100644 --- a/webapp/src/views/HomeView.vue +++ b/webapp/src/views/HomeView.vue @@ -1,7 +1,7 @@ {{ formatNumber(inverter.limit_relative, 0) }}%
Data Age: {{ inverter.data_age }} seconds @@ -178,15 +179,16 @@ Limit:
- + %
- W @@ -333,6 +335,7 @@ import type { EventlogItems } from '@/types/EventlogStatus'; import type { Inverters } from '@/types/LiveDataStatus'; import type { LimitStatus } from '@/types/LimitStatus'; import type { LimitConfig } from '@/types/LimitConfig'; +import { formatNumber } from '@/utils'; export default defineComponent({ components: { @@ -424,17 +427,18 @@ export default defineComponent({ } }, computed: { - currentLimitAbsolute(): number { + currentLimitAbsolute(): string { if (this.currentLimitList.max_power > 0) { - return Number((this.currentLimitList.limit_relative * this.currentLimitList.max_power / 100).toFixed(1)); + return formatNumber(this.currentLimitList.limit_relative * this.currentLimitList.max_power / 100, 2); } - return 0; + return "0"; }, - currentLimitRelative(): number { - return Number((this.currentLimitList.limit_relative).toFixed(1)); + currentLimitRelative(): string { + return formatNumber(this.currentLimitList.limit_relative, 2); } }, methods: { + formatNumber, getInitialData() { this.dataLoading = true; fetch("/api/livedata/status")