use truncation instead of rounding down or rounding to the nearest value when numerical calculations exceed precision limits

This commit is contained in:
MaysWind
2025-09-09 20:46:51 +08:00
parent d4603a1892
commit 7e2e1a4ad3
13 changed files with 36 additions and 36 deletions
+9 -9
View File
@@ -510,7 +510,7 @@ export const useAccountsStore = defineStore('accounts', () => {
continue;
}
netAssets += Math.floor(balance);
netAssets += Math.trunc(balance);
}
}
@@ -546,7 +546,7 @@ export const useAccountsStore = defineStore('accounts', () => {
continue;
}
totalAssets += Math.floor(balance);
totalAssets += Math.trunc(balance);
}
}
@@ -582,7 +582,7 @@ export const useAccountsStore = defineStore('accounts', () => {
continue;
}
totalLiabilities -= Math.floor(balance);
totalLiabilities -= Math.trunc(balance);
}
}
@@ -623,11 +623,11 @@ export const useAccountsStore = defineStore('accounts', () => {
}
if (accountsBalance[i].isAsset) {
totalBalance += Math.floor(balance);
totalBalance += Math.trunc(balance);
} else if (accountsBalance[i].isLiability) {
totalBalance -= Math.floor(balance);
totalBalance -= Math.trunc(balance);
} else {
totalBalance += Math.floor(balance);
totalBalance += Math.trunc(balance);
}
}
}
@@ -737,11 +737,11 @@ export const useAccountsStore = defineStore('accounts', () => {
}
if (subAccount.isAsset) {
totalBalance += Math.floor(balance);
totalBalance += Math.trunc(balance);
} else if (subAccount.isLiability) {
totalBalance -= Math.floor(balance);
totalBalance -= Math.trunc(balance);
} else {
totalBalance += Math.floor(balance);
totalBalance += Math.trunc(balance);
}
}
}
+2 -2
View File
@@ -164,13 +164,13 @@ export const useOverviewStore = defineStore('overview', () => {
const expenseAmount = exchangeRatesStore.getExchangedAmount(amount.expenseAmount, amount.currency, defaultCurrency);
if (isNumber(incomeAmount)) {
totalIncomeAmount += Math.floor(incomeAmount);
totalIncomeAmount += Math.trunc(incomeAmount);
} else {
hasUnCalculatedTotalIncome = true;
}
if (isNumber(expenseAmount)) {
totalExpenseAmount += Math.floor(expenseAmount);
totalExpenseAmount += Math.trunc(expenseAmount);
} else {
hasUnCalculatedTotalExpense = true;
}
+2 -2
View File
@@ -260,7 +260,7 @@ export const useStatisticsStore = defineStore('statistics', () => {
continue;
}
amount = Math.floor(finalAmount);
amount = Math.trunc(finalAmount);
}
if (account.isLiability) {
@@ -481,7 +481,7 @@ export const useStatisticsStore = defineStore('statistics', () => {
const amount = exchangeRatesStore.getExchangedAmount(item.amount, item.account.currency, defaultCurrency);
if (isNumber(amount)) {
item.amountInDefaultCurrency = Math.floor(amount);
item.amountInDefaultCurrency = Math.trunc(amount);
}
} else if (item.account && item.account.currency === defaultCurrency) {
item.amountInDefaultCurrency = item.amount;
+6 -6
View File
@@ -410,9 +410,9 @@ export const useTransactionsStore = defineStore('transactions', () => {
}
}
transactionMonthList.totalAmount.expense = Math.floor(totalExpense);
transactionMonthList.totalAmount.expense = Math.trunc(totalExpense);
transactionMonthList.totalAmount.incompleteExpense = incomplete || hasUnCalculatedTotalExpense;
transactionMonthList.totalAmount.income = Math.floor(totalIncome);
transactionMonthList.totalAmount.income = Math.trunc(totalIncome);
transactionMonthList.totalAmount.incompleteIncome = incomplete || hasUnCalculatedTotalIncome;
for (const day in transactionMonthList.dailyTotalAmounts) {
@@ -431,9 +431,9 @@ export const useTransactionsStore = defineStore('transactions', () => {
const dailyTotalAmount = dailyTotalAmounts[day];
transactionMonthList.dailyTotalAmounts[day] = {
expense: Math.floor(dailyTotalAmount.expense),
expense: Math.trunc(dailyTotalAmount.expense),
incompleteExpense: incomplete || dailyTotalAmount.incompleteExpense,
income: Math.floor(dailyTotalAmount.income),
income: Math.trunc(dailyTotalAmount.income),
incompleteIncome: incomplete || dailyTotalAmount.incompleteIncome
};
}
@@ -568,12 +568,12 @@ export const useTransactionsStore = defineStore('transactions', () => {
const exchangedNewValue = exchangeRatesStore.getExchangedAmount(newValue, sourceAccount.currency, destinationAccount.currency);
if (isNumber(decimalNumberCount) && isNumber(exchangedOldValue)) {
oldValue = Math.floor(exchangedOldValue);
oldValue = Math.trunc(exchangedOldValue);
oldValue = getAmountWithDecimalNumberCount(oldValue, decimalNumberCount);
}
if (isNumber(decimalNumberCount) && isNumber(exchangedNewValue)) {
newValue = Math.floor(exchangedNewValue);
newValue = Math.trunc(exchangedNewValue);
newValue = getAmountWithDecimalNumberCount(newValue, decimalNumberCount);
} else {
return;