decimal places setting

This commit is contained in:
vabene1111
2025-08-17 10:36:46 +02:00
parent a3460bc023
commit 7f8587922d
3 changed files with 7 additions and 4 deletions

View File

@@ -22,8 +22,8 @@
<tbody>
<tr v-for="p in propertyList" :key="p.id">
<td>{{ p.name }}</td>
<td>{{ $n(p.propertyAmountPerServing) }} {{ p.unit }}</td>
<td>{{ $n(p.propertyAmountTotal) }} {{ p.unit }}</td>
<td>{{ $n(roundDecimals(p.propertyAmountPerServing)) }} {{ p.unit }}</td>
<td>{{ $n(roundDecimals(p.propertyAmountTotal)) }} {{ p.unit }}</td>
<td v-if="sourceSelectedToShow == 'food'">
<v-btn @click="dialogProperty = p; dialog = true" variant="plain" color="warning" icon="fa-solid fa-triangle-exclamation" size="small" class="d-print-none"
v-if="p.missingValue"></v-btn>
@@ -86,6 +86,7 @@ import {ApiApi, PropertyType, Recipe} from "@/openapi";
import VClosableCardTitle from "@/components/dialogs/VClosableCardTitle.vue";
import ModelEditDialog from "@/components/dialogs/ModelEditDialog.vue";
import {ErrorMessageType, useMessageStore} from "@/stores/MessageStore";
import {roundDecimals} from "@/utils/number_utils.ts";
type PropertyWrapper = {
id: number,

View File

@@ -27,7 +27,7 @@
<v-divider class="mb-3"></v-divider>
<v-text-field v-model="useUserPreferenceStore().userSettings.defaultUnit" :label="$t('Default_Unit')"></v-text-field>
<!-- <v-text-field v-model="useUserPreferenceStore().userSettings.ingredientDecimals" :label="$t('Decimals')"></v-text-field>-->
<v-number-input v-model="useUserPreferenceStore().userSettings.ingredientDecimals" :label="$t('Decimals')"></v-number-input>
<!-- <v-select-->
<!-- :label="$t('DefaultPage')"-->

View File

@@ -1,9 +1,11 @@
import {useUserPreferenceStore} from "@/stores/UserPreferenceStore.ts";
/**
* round to the number of decimals specified in user preferences
* @param num number to round
*/
export function roundDecimals(num: number) {
let decimals = 2 //TODO get user preference
let decimals = useUserPreferenceStore().userSettings.ingredientDecimals
return Number(num.toFixed(decimals))
}