Fix decimal points in metrics

This commit is contained in:
rijkvanzanten
2021-06-18 14:11:26 -04:00
parent c35b469b0a
commit 05fa39e85f
3 changed files with 21 additions and 6 deletions

View File

@@ -1,7 +1,8 @@
import { RequestError } from '@/api';
import { createI18n } from 'vue-i18n';
import availableLanguages from './available-languages.yaml';
import dateFormats from './date-formats.yaml';
import datetimeFormats from './date-formats.yaml';
import numberFormats from './number-formats.yaml';
import enUSBase from './translations/en-US.yaml';
export const i18n = createI18n({
@@ -11,8 +12,9 @@ export const i18n = createI18n({
messages: {
'en-US': enUSBase,
},
datetimeFormats: dateFormats,
silentTranslationWarn: true,
datetimeFormats,
numberFormats,
});
export type Language = keyof typeof availableLanguages;

View File

@@ -0,0 +1,12 @@
en-US:
currency:
style: 'currency'
currency: 'USD'
notation: standard
decimal:
style: 'decimal'
minimumFractionDigits: 2
maximumFractionDigits: 2
percent:
style: 'percent'
useGrouping: false

View File

@@ -68,7 +68,10 @@ export default defineComponent({
return abbreviateNumber(metric.value);
}
return n(Number(metric.value));
return n(Number(metric.value), 'decimal', {
minimumFractionDigits: props.options.decimals,
maximumFractionDigits: props.options.decimals,
} as any);
});
const color = computed(() => {
@@ -126,9 +129,7 @@ export default defineComponent({
},
});
metric.value = Number(res.data.data[0][`${props.options.field}_${props.options.function}`]).toFixed(
props.options.decimals
);
metric.value = Number(res.data.data[0][`${props.options.field}_${props.options.function}`]);
} catch (err) {
// oh no
} finally {