format percents better

This commit is contained in:
Robert Dyer
2024-07-01 13:46:18 -05:00
parent 96d0fc109c
commit bc1cd4e7e8
3 changed files with 13 additions and 6 deletions
+6 -4
View File
@@ -1,5 +1,5 @@
const api = require('@actual-app/api');
const { closeBudget, ensurePayee, getAccountBalance, getAccountNote, getLastTransactionDate, openBudget } = require('./utils');
const { closeBudget, ensurePayee, getAccountBalance, getAccountNote, getLastTransactionDate, openBudget, showPercent } = require('./utils');
require("dotenv").config();
(async () => {
@@ -17,7 +17,7 @@ require("dotenv").config();
if (note) {
if (note.indexOf('interestRate:') > -1 && note.indexOf('interestDay:') > -1) {
const interestRate = parseFloat(note.split('interestRate:')[1].split(' ')[0]);
let interestRate = parseFloat(note.split('interestRate:')[1].split(' ')[0]);
const interestDay = parseInt(note.split('interestDay:')[1].split(' ')[0]);
const interestTransactionDate = new Date();
@@ -38,11 +38,13 @@ require("dotenv").config();
const balance = await getAccountBalance(account, interestTransactionDate);
const compoundedInterest = Math.round(balance * (Math.pow(1 + interestRate / 12, 1) - 1));
interestRate = showPercent(interestRate);
console.log(`== ${account.name} ==`);
console.log(` -> Balance: ${balance}`);
console.log(` as of ${lastDate}`);
console.log(` -> # days: ${daysPassed}`);
console.log(` -> Interest: ${compoundedInterest}`)
console.log(` -> Interest: ${compoundedInterest} (${interestRate})`)
if (compoundedInterest) {
await api.importTransactions(account.id, [{
@@ -50,7 +52,7 @@ require("dotenv").config();
payee: payeeId,
amount: compoundedInterest,
cleared: true,
notes: `Interest for 1 month at ${100*interestRate}%`,
notes: `Interest for 1 month at ${interestRate}`,
}]);
}
}
+5
View File
@@ -137,4 +137,9 @@ module.exports = {
setTimeout(resolve, ms);
});
},
showPercent: function (pct) {
return Number(pct).toLocaleString(undefined,
{ style: 'percent', maximumFractionDigits: 2 })
},
};
+2 -2
View File
@@ -1,6 +1,6 @@
const api = require('@actual-app/api');
const jsdom = require("jsdom");
const { closeBudget, ensurePayee, getAccountBalance, getAccountNote, openBudget, sleep } = require('./utils');
const { closeBudget, ensurePayee, getAccountBalance, getAccountNote, openBudget, showPercent, sleep } = require('./utils');
require("dotenv").config();
async function getZestimate(URL) {
@@ -56,7 +56,7 @@ async function getZestimate(URL) {
amount: diff,
cleared: true,
reconciled: true,
notes: `Update Zestimate to ${zestimate * ownership / 100} (${zestimate / 100}*${ownership * 100}%)`,
notes: `Update Zestimate to ${zestimate * ownership / 100} (${zestimate / 100}*${showPercent(ownership)})`,
}]);
}