mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-16 07:57:33 +08:00
use truncation instead of rounding down or rounding to the nearest value when numerical calculations exceed precision limits
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user