Skip to content

A local-first personal finance app

[AI] Use amounts instead of cents in rule formulas (#8717)

youngcw1ad8477abdc4
diff --git a/packages/desktop-client/src/components/formula/formulaCatalog.ts b/packages/desktop-client/src/components/formula/formulaCatalog.ts
index 32484cbfae..3264100da8 100644
--- a/packages/desktop-client/src/components/formula/formulaCatalog.ts
+++ b/packages/desktop-client/src/components/formula/formulaCatalog.ts
@@ -1134,7 +1134,7 @@ export function getFormulaFunctionCatalog(): Record<
category: 'other',
modes: ['query', 'transaction'],
description: t(
- "Balance for an account. In rule formulas, this is the running balance (in cents) at this transaction, same cutoff as balance (use the balance variable instead for the current account). In report/query formulas, this is the account's current balance (in money/display units). Use a quoted account id for a deterministic match, or a quoted account name.",
+ "Balance for an account. In rule formulas, this is the running balance at this transaction, same cutoff as balance (use the balance variable instead for the current account). In report/query formulas, this is the account's current balance. Use a quoted account id for a deterministic match, or a quoted account name.",
),
parameters: [
{
@@ -1336,7 +1336,7 @@ export function getRuleFieldCompletions(): Completion[] {
section: ruleFieldSection,
boost: 5,
info: t(
- 'Transaction amount in cents. Use for calculations and comparisons.\n\nExample: =amount / 100 to get dollar value',
+ 'Transaction amount. Use for calculations and comparisons.\n\nExample: =amount * 1.05 to add 5%',
),
},
{
@@ -1453,7 +1453,7 @@ export function getRuleFieldCompletions(): Completion[] {
section: ruleFieldSection,
boost: 5,
info: t(
- 'The amount of the parent transaction in cents in split transactions.\n\nExample: =(parent_amount / 100) * .05',
+ 'The amount of the parent transaction in split transactions.\n\nExample: =parent_amount * .05',
),
},
{
diff --git a/packages/docs/docs/experimental/formulas.md b/packages/docs/docs/experimental/formulas.md
index e852685149..1f7a498495 100644
--- a/packages/docs/docs/experimental/formulas.md
+++ b/packages/docs/docs/experimental/formulas.md
@@ -47,143 +47,143 @@ This list documents formula functions that are useful in Actual. The in-app **au
If a function isn’t listed here, it still might work. Actual uses HyperFormula under the hood, so you can also refer to [HyperFormula’s built-in functions list](https://hyperformula.handsontable.com/guide/built-in-functions.html).
:::
-| Function | Available in | Description | Syntax example | Optional params |
-| ------------------------------- | ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------- |
-| `ABS` | Query, Rules | Returns the absolute value of a number. | `=ABS(-42)` | — |
-| `AND` | Query, Rules | Returns TRUE if all arguments are TRUE. | `=AND(1=1, 2=2)` | Accepts more than 2 conditions |
-| `AVERAGE` | Query | Returns the average of all numbers in a range. | `=AVERAGE(1, 2, 3)` | Accepts more than 2 values |
-| `AVERAGEA` | Query | Returns the average, including text and logical values. | `=AVERAGEA(1, TRUE, "2")` | Accepts more than 2 values |
-| `BALANCE_OF` | Query, Rules | Balance for an account; pass a quoted account id or exact account name. In rules, the running balance (cents) at this transaction; in reports, the account's current balance (money units). | `=BALANCE_OF("550e8400-e29b-41d4-a716-446655440000"); =BALANCE_OF("Checking")` | — |
-| `BUDGET_QUERY` | Query | Returns a budget dimension total for a set of categories over a month range. Dimension is one of: `budgeted`, `spent`, `balance_start`, `balance_end`, `goal`. | `=BUDGET_QUERY("spent", QUERY_EXTRACT_CATEGORIES("q"), QUERY_EXTRACT_TIMEFRAME_START("q"), QUERY_EXTRACT_TIMEFRAME_END("q"))` | — |
-| `CEILING` | Query, Rules | Rounds up to nearest multiple of significance. | `=CEILING(10.2, 1)` | — |
-| `CHAR` | Query, Rules | Converts number to character. | `=CHAR(65)` | — |
-| `CHOOSE` | Query | Returns value from list based on index. | `=CHOOSE(2, "A", "B", "C")` | Accepts more than 2 values |
-| `CLEAN` | Rules | Removes non-printable characters from text. | `=CLEAN(notes)` | — |
-| `CODE` | Query, Rules | Returns numeric code for first character. | `=CODE("A")` | — |
-| `CONCATENATE` | Query, Rules | Combines several text strings into one. | `=CONCATENATE("Paid ", payee_name)` | Accepts more than 2 texts |
-| `COS` | Query | Returns the cosine of an angle. | `=COS(1)` | — |
-| `COUNT` | Query | Counts the number of numeric values. | `=COUNT(1, 2, "x")` | Accepts more than 2 values |
-| `COUNTA` | Query | Counts non-empty values. | `=COUNTA(1, "", "x")` | Accepts more than 2 values |
-| `COUNTBLANK` | Query | Counts empty cells. | `=COUNTBLANK(A1:A10)` | — |
-| `COUNTIF` | Query | Counts cells that meet a criteria. | `=COUNTIF(A1:A10, ">0")` | — |
-| `COUNTIFS` | Query | Counts cells that meet multiple criteria. | `=COUNTIFS(A1:A10, ">0", B1:B10, "<=5")` | Repeat `(range, criteria)` pairs |
-| `CUMIPMT` | Query, Rules | Calculates cumulative interest paid between two periods. | `=CUMIPMT(0.05/12, 60, 20000, 1, 12, 0)` | — |
-| `CUMPRINC` | Query, Rules | Calculates cumulative principal paid between two periods. | `=CUMPRINC(0.05/12, 60, 20000, 1, 12, 0)` | — |
-| `DATE` | Query, Rules | Returns date as number of days since null date. | `=DATE(2025, 12, 16)` | — |
-| `DATEDIF` | Query, Rules | Calculates distance between dates. | `=DATEDIF("2025-01-01", "2025-12-31", "D")` | — |
-| `DATEVALUE` | Rules | Parses a date string and returns it as a number. | `=DATEVALUE("2025-12-16")` | — |
-| `DAY` | Query, Rules | Returns the day from a date. | `=DAY(date)` | — |
-| `DAYS` | Query, Rules | Calculates difference between dates in days. | `=DAYS("2025-12-31", "2025-12-01")` | — |
-| `EDATE` | Query, Rules | Returns date shifted by specified months. | `=EDATE(date, 1)` | — |
-| `EOMONTH` | Query, Rules | Returns last day of month after specified months. | `=EOMONTH(date, 0)` | — |
-| `EXACT` | Query, Rules | Returns TRUE if texts are exactly the same. | `=EXACT("A", "a")` | — |
-| `EXP` | Query | Returns e raised to the power of number. | `=EXP(1)` | — |
-| `FALSE` | Query, Rules | Returns the logical value FALSE. | `=FALSE()` | — |
-| `FIND` | Query, Rules | Finds text within text (case-sensitive). | `=FIND("foo", notes)` | — |
-| `FIXED` | Query, Rules | Formats a number to a fixed amount of decimal places. | `=FIXED(1234.5, 2)` | — |
-| `FLOOR` | Query, Rules | Rounds down to nearest multiple of significance. | `=FLOOR(10.8, 1)` | — |
-| `FORMATCURRENCY` | Query, Rules | Formats a number as currency using your app currency, number format, symbol position, and spacing settings by default. | `=FORMATCURRENCY(1234.5)` | `symbol`, `decimals`, `thousandsSeparator`, `decimalSeparator`, `symbolPosition`, `spaceBetweenAmountAndSymbol` |
-| `FORMATNUMBER` | Query, Rules | Formats a number using your app number format settings by default. | `=FORMATNUMBER(1234.5, 2)` | `decimals`, `thousandsSeparator`, `decimalSeparator` |
-| `FV` | Query | Calculates future value of investment. | `=FV(0.05/12, 12, -100)` | — |
-| `FVSCHEDULE` | Query | Calculates future value of a principal using a schedule of varying interest rates. | `=FVSCHEDULE(1000, {0.05;0.06;0.07})` | — |
-| `HLOOKUP` | Query | Searches horizontally in first row and returns value. | `=HLOOKUP("key", A1:D10, 2, TRUE)` | — |
-| `IF` | Query, Rules | Returns one value if condition is TRUE, another if FALSE. | `=IF(amount<0, "Expense", "Income")` | — |
-| `IFERROR` | Query, Rules | Returns value if no error, otherwise returns alternative. | `=IFERROR(1/0, 0)` | — |
-| `IFNA` | Query, Rules | Returns value if not #N/A error, otherwise returns alternative. | `=IFNA(VLOOKUP("x", A1:B10, 2, FALSE), 0)` | — |
-| `IFS` | Query, Rules | Checks multiple conditions and returns corresponding values. | `=IFS(amount<0, "Expense", amount>0, "Income")` | Repeat `(condition, value)` pairs |
-| `INDEX` | Query | Returns value at specified row and column. | `=INDEX(A1:C10, 2, 3)` | — |
-| `INTEGER_TO_AMOUNT` | Query, Rules | Converts integer amount to decimal amount (e.g., 1234 -> 12.34). | `=INTEGER_TO_AMOUNT(amount, 2)` | `decimal_places` (default: 2) |
-| `INT` | Rules | Rounds down to nearest integer. | `=INT(10.9)` | — |
-| `IPMT` | Query, Rules | Calculates the interest portion of a loan payment for a given period. | `=IPMT(0.05/12, 1, 60, 20000)` | — |
-| `IRR` | Query | Calculates internal rate of return. | `=IRR(A1:A12)` | — |
-| `ISEVEN` | Rules | Returns TRUE if number is even. | `=ISEVEN(10)` | — |
-| `ISODD` | Rules | Returns TRUE if number is odd. | `=ISODD(11)` | — |
-| `ISBLANK` | Query, Rules | Returns TRUE if value is blank. | `=ISBLANK(notes)` | — |
-| `ISERROR` | Query, Rules | Returns TRUE if value is any error. | `=ISERROR(1/0)` | — |
-| `ISLOGICAL` | Query, Rules | Returns TRUE if value is logical (TRUE/FALSE). | `=ISLOGICAL(TRUE())` | — |
-| `ISNA` | Query, Rules | Returns TRUE if value is #N/A error. | `=ISNA(NA())` | — |
-| `ISNUMBER` | Query, Rules | Returns TRUE if value is a number. | `=ISNUMBER(amount)` | — |
-| `ISOWEEKNUM` | Rules | Returns ISO week number. | `=ISOWEEKNUM(date)` | — |
-| `ISREF` | Query | Returns TRUE if value is a reference. | `=ISREF(A1)` | — |
-| `ISTEXT` | Query, Rules | Returns TRUE if value is text. | `=ISTEXT(notes)` | — |
-| `LEFT` | Query, Rules | Returns leftmost characters from text. | `=LEFT(imported_payee, 10)` | — |
-| `LEN` | Query, Rules | Returns length of text. | `=LEN(notes)` | — |
-| `LN` | Query | Returns the natural logarithm. | `=LN(10)` | — |
-| `LOG` | Query | Returns the logarithm to specified base. | `=LOG(100, 10)` | — |
-| `LOG10` | Query | Returns the base-10 logarithm. | `=LOG10(1000)` | — |
-| `LOOKUP` | Query | Looks up values in a vector or array. | `=LOOKUP("x", A1:A10)` | — |
-| `LOWER` | Query, Rules | Converts text to lowercase. | `=LOWER(notes)` | — |
-| `MATCH` | Query | Returns position of value in array. | `=MATCH("x", A1:A10, 0)` | — |
-| `MAX` | Query | Returns the maximum value. | `=MAX(1, 2, 3)` | Accepts more than 2 values |
-| `MAXA` | Query | Returns the maximum value, including text and logical values. | `=MAXA(1, TRUE, "2")` | Accepts more than 2 values |
-| `MEDIAN` | Query | Returns the median value. | `=MEDIAN(1, 2, 100)` | Accepts more than 2 values |
-| `MID` | Query, Rules | Returns substring from specified position. | `=MID(notes, 1, 10)` | — |
-| `MIN` | Query | Returns the minimum value. | `=MIN(1, 2, 3)` | Accepts more than 2 values |
-| `MINA` | Query | Returns the minimum value, including text and logical values. | `=MINA(1, TRUE, "2")` | Accepts more than 2 values |
-| `MIRR` | Query | Calculates the modified internal rate of return for a series of cash flows. | `=MIRR(A1:A12, 0.1, 0.12)` | — |
-| `MOD` | Query, Rules | Returns the remainder of division. | `=MOD(10, 3)` | — |
-| `MODE` | Query | Returns the most frequently occurring value. | `=MODE(1, 1, 2)` | Accepts more than 2 values |
-| `MONTH` | Query, Rules | Returns the month from a date. | `=MONTH(date)` | — |
-| `N` | Rules | Converts value to a number. | `=N(TRUE())` | — |
-| `NETWORKDAYS` | Query | Returns number of working days between dates. | `=NETWORKDAYS("2025-12-01", "2025-12-31")` | — |
-| `NOT` | Query, Rules | Reverses the logical value. | `=NOT(amount<0)` | — |
-| `NOW` | Query, Rules | Returns current date and time. | `=NOW()` | — |
-| `NPER` | Query, Rules | Calculates the number of payment periods for a loan or investment. | `=NPER(0.05/12, -200, 10000)` | — |
-| `NPV` | Query | Calculates net present value. | `=NPV(0.1, -1000, 200, 300)` | Accepts more than 2 values |
-| `OR` | Query, Rules | Returns TRUE if any argument is TRUE. | `=OR(amount<0, amount>0)` | Accepts more than 2 conditions |
-| `PERCENTILE` | Query | Returns the k-th percentile. | `=PERCENTILE(A1:A100, 0.9)` | — |
-| `PI` | Query | Returns the value of PI. | `=PI()` | — |
-| `PMT` | Query | Calculates payment for a loan. | `=PMT(0.05/12, 60, 10000)` | — |
-| `POWER` | Query, Rules | Returns base raised to the power of exponent. | `=POWER(2, 8)` | — |
-| `PPMT` | Query, Rules | Calculates the principal portion of a loan payment for a given period. | `=PPMT(0.05/12, 1, 60, 20000)` | — |
-| `PROPER` | Query, Rules | Capitalizes first letter of each word. | `=PROPER(notes)` | — |
-| `PRODUCT` | Query | Returns the product of all numbers. | `=PRODUCT(2, 3, 4)` | Accepts more than 2 values |
-| `PV` | Query | Calculates present value of investment. | `=PV(0.05/12, 12, -100)` | — |
-| `QUARTILE` | Query | Returns the quartile of a dataset. | `=QUARTILE(A1:A100, 1)` | — |
-| `QUERY` | Query | Execute a query and return the result. | `=QUERY("expenses")` | — |
-| `QUERY_COUNT` | Query | Execute a query and return the number of matching rows. | `=QUERY_COUNT("expenses")` | — |
-| `QUERY_EXTRACT_CATEGORIES` | Query | Determines which categories to include based on a named query's category filters; used as the `categories` argument in `BUDGET_QUERY`. | `=QUERY_EXTRACT_CATEGORIES("expenses")` | — |
-| `QUERY_EXTRACT_TIMEFRAME_END` | Query | Extracts the end month from a named query's date range; used as the `endMonth` argument in `BUDGET_QUERY`. | `=QUERY_EXTRACT_TIMEFRAME_END("expenses")` | — |
-| `QUERY_EXTRACT_TIMEFRAME_START` | Query | Extracts the start month from a named query's date range; used as the `startMonth` argument in `BUDGET_QUERY`. | `=QUERY_EXTRACT_TIMEFRAME_START("expenses")` | — |
-| `RANK` | Query | Returns the rank of a number in a list. | `=RANK(10, A1:A10, 0)` | — |
-| `RATE` | Query | Calculates interest rate per period. | `=RATE(60, -200, 10000)` | — |
-| `REPLACE` | Query, Rules | Replaces substring at specified position. | `=REPLACE(notes, 1, 5, "")` | — |
-| `REPT` | Query, Rules | Repeats text specified number of times. | `=REPT("*", 10)` | — |
-| `RIGHT` | Query, Rules | Returns rightmost characters from text. | `=RIGHT(imported_payee, 4)` | — |
-| `ROUND` | Query, Rules | Rounds a number to specified decimals. | `=ROUND(amount/100, 2)` | — |
-| `ROUNDDOWN` | Query, Rules | Rounds down to specified decimals. | `=ROUNDDOWN(amount/100, 0)` | — |
-| `ROUNDUP` | Query, Rules | Rounds up to specified decimals. | `=ROUNDUP(amount/100, 0)` | — |
-| `SEARCH` | Query, Rules | Finds text within text (case-insensitive, supports wildcards). | `=SEARCH("foo", notes)` | — |
-| `SIGN` | Rules | Returns -1 for negative, 0 for zero, 1 for positive. | `=SIGN(amount)` | — |
-| `SIN` | Query | Returns the sine of an angle. | `=SIN(1)` | — |
-| `SPLIT` | Rules | Splits text by space and returns part at index. | `=SPLIT(imported_payee, 0)` | — |
-| `SQRT` | Query, Rules | Returns the square root. | `=SQRT(9)` | — |
-| `STDEV` | Query | Returns the standard deviation of a sample. | `=STDEV(A1:A10)` | — |
-| `STDEVP` | Query | Returns the standard deviation of a population. | `=STDEVP(A1:A10)` | — |
-| `SUBSTITUTE` | Query, Rules | Replaces occurrences of text. | `=SUBSTITUTE(imported_payee, " 12345", "")` | — |
-| `SUM` | Query, Rules | Returns the sum of all numbers in a range. | `=SUM(1, 2, 3)` | Accepts more than 2 values |
-| `SUMIF` | Query | Sums cells that meet a criteria. | `=SUMIF(A1:A10, ">0", B1:B10)` | — |
-| `SUMIFS` | Query | Sums cells that meet multiple criteria. | `=SUMIFS(B1:B10, A1:A10, ">0", C1:C10, "X")` | Repeat `(range, criteria)` pairs |
-| `SUMPRODUCT` | Query | Multiplies corresponding elements and returns the sum. | `=SUMPRODUCT(A1:A10, B1:B10)` | Accepts more arrays |
-| `SUMSQ` | Query | Returns the sum of the squares. | `=SUMSQ(1, 2, 3)` | Accepts more than 2 values |
-| `SWITCH` | Query, Rules | Matches expression against values and returns corresponding result. | `=SWITCH(category_name, "Groceries", "Food", "Fuel", "Transport")` | Repeat `(value, result)` pairs; default supported |
-| `T` | Rules | Returns text if value is text, empty string otherwise. | `=T(notes)` | — |
-| `TAN` | Query | Returns the tangent of an angle. | `=TAN(1)` | — |
-| `TEXT` | Query, Rules | Converts number to text with format. | `=TEXT(date, "MMMM yyyy")` | — |
-| `TODAY` | Query, Rules | Returns current date. | `=TODAY()` | — |
-| `TRIM` | Query, Rules | Removes extra spaces from text. | `=TRIM(notes)` | — |
-| `TRUNC` | Rules | Truncates number to specified decimals. | `=TRUNC(amount/100, 0)` | — |
-| `TRUE` | Query, Rules | Returns the logical value TRUE. | `=TRUE()` | — |
-| `UPPER` | Query, Rules | Converts text to uppercase. | `=UPPER(notes)` | — |
-| `VALUE` | Rules | Converts text to a number. | `=VALUE("123.45")` | — |
-| `VAR` | Query | Returns the variance of a sample. | `=VAR(A1:A10)` | — |
-| `VARP` | Query | Returns the variance of a population. | `=VARP(A1:A10)` | — |
-| `VLOOKUP` | Query | Searches vertically in first column and returns value. | `=VLOOKUP("key", A1:D10, 2, TRUE)` | — |
-| `WEEKDAY` | Query, Rules | Returns day of week (1-7). | `=WEEKDAY(date, 1)` | — |
-| `WEEKNUM` | Query, Rules | Returns week number of year. | `=WEEKNUM(date, 1)` | — |
-| `XNPV` | Query | Calculates net present value for cash flows on irregular (dated) intervals. | `=XNPV(0.1, A1:A5, B1:B5)` | — |
-| `XOR` | Query, Rules | Returns TRUE if odd number of arguments are TRUE. | `=XOR(TRUE(), FALSE())` | Accepts more than 2 conditions |
-| `YEAR` | Query, Rules | Returns the year from a date. | `=YEAR(date)` | — |
+| Function | Available in | Description | Syntax example | Optional params |
+| ------------------------------- | ------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------- |
+| `ABS` | Query, Rules | Returns the absolute value of a number. | `=ABS(-42)` | — |
+| `AND` | Query, Rules | Returns TRUE if all arguments are TRUE. | `=AND(1=1, 2=2)` | Accepts more than 2 conditions |
+| `AVERAGE` | Query | Returns the average of all numbers in a range. | `=AVERAGE(1, 2, 3)` | Accepts more than 2 values |
+| `AVERAGEA` | Query | Returns the average, including text and logical values. | `=AVERAGEA(1, TRUE, "2")` | Accepts more than 2 values |
+| `BALANCE_OF` | Query, Rules | Balance for an account; pass a quoted account id or exact account name. In rules, the running balance at this transaction; in reports, the account's current balance. | `=BALANCE_OF("550e8400-e29b-41d4-a716-446655440000"); =BALANCE_OF("Checking")` | — |
+| `BUDGET_QUERY` | Query | Returns a budget dimension total for a set of categories over a month range. Dimension is one of: `budgeted`, `spent`, `balance_start`, `balance_end`, `goal`. | `=BUDGET_QUERY("spent", QUERY_EXTRACT_CATEGORIES("q"), QUERY_EXTRACT_TIMEFRAME_START("q"), QUERY_EXTRACT_TIMEFRAME_END("q"))` | — |
+| `CEILING` | Query, Rules | Rounds up to nearest multiple of significance. | `=CEILING(10.2, 1)` | — |
+| `CHAR` | Query, Rules | Converts number to character. | `=CHAR(65)` | — |
+| `CHOOSE` | Query | Returns value from list based on index. | `=CHOOSE(2, "A", "B", "C")` | Accepts more than 2 values |
+| `CLEAN` | Rules | Removes non-printable characters from text. | `=CLEAN(notes)` | — |
+| `CODE` | Query, Rules | Returns numeric code for first character. | `=CODE("A")` | — |
+| `CONCATENATE` | Query, Rules | Combines several text strings into one. | `=CONCATENATE("Paid ", payee_name)` | Accepts more than 2 texts |
+| `COS` | Query | Returns the cosine of an angle. | `=COS(1)` | — |
+| `COUNT` | Query | Counts the number of numeric values. | `=COUNT(1, 2, "x")` | Accepts more than 2 values |
+| `COUNTA` | Query | Counts non-empty values. | `=COUNTA(1, "", "x")` | Accepts more than 2 values |
+| `COUNTBLANK` | Query | Counts empty cells. | `=COUNTBLANK(A1:A10)` | — |
+| `COUNTIF` | Query | Counts cells that meet a criteria. | `=COUNTIF(A1:A10, ">0")` | — |
+| `COUNTIFS` | Query | Counts cells that meet multiple criteria. | `=COUNTIFS(A1:A10, ">0", B1:B10, "<=5")` | Repeat `(range, criteria)` pairs |
+| `CUMIPMT` | Query, Rules | Calculates cumulative interest paid between two periods. | `=CUMIPMT(0.05/12, 60, 20000, 1, 12, 0)` | — |
+| `CUMPRINC` | Query, Rules | Calculates cumulative principal paid between two periods. | `=CUMPRINC(0.05/12, 60, 20000, 1, 12, 0)` | — |
+| `DATE` | Query, Rules | Returns date as number of days since null date. | `=DATE(2025, 12, 16)` | — |
+| `DATEDIF` | Query, Rules | Calculates distance between dates. | `=DATEDIF("2025-01-01", "2025-12-31", "D")` | — |
+| `DATEVALUE` | Rules | Parses a date string and returns it as a number. | `=DATEVALUE("2025-12-16")` | — |
+| `DAY` | Query, Rules | Returns the day from a date. | `=DAY(date)` | — |
+| `DAYS` | Query, Rules | Calculates difference between dates in days. | `=DAYS("2025-12-31", "2025-12-01")` | — |
+| `EDATE` | Query, Rules | Returns date shifted by specified months. | `=EDATE(date, 1)` | — |
+| `EOMONTH` | Query, Rules | Returns last day of month after specified months. | `=EOMONTH(date, 0)` | — |
+| `EXACT` | Query, Rules | Returns TRUE if texts are exactly the same. | `=EXACT("A", "a")` | — |
+| `EXP` | Query | Returns e raised to the power of number. | `=EXP(1)` | — |
+| `FALSE` | Query, Rules | Returns the logical value FALSE. | `=FALSE()` | — |
+| `FIND` | Query, Rules | Finds text within text (case-sensitive). | `=FIND("foo", notes)` | — |
+| `FIXED` | Query, Rules | Formats a number to a fixed amount of decimal places. | `=FIXED(1234.5, 2)` | — |
+| `FLOOR` | Query, Rules | Rounds down to nearest multiple of significance. | `=FLOOR(10.8, 1)` | — |
+| `FORMATCURRENCY` | Query, Rules | Formats a number as currency using your app currency, number format, symbol position, and spacing settings by default. | `=FORMATCURRENCY(1234.5)` | `symbol`, `decimals`, `thousandsSeparator`, `decimalSeparator`, `symbolPosition`, `spaceBetweenAmountAndSymbol` |
+| `FORMATNUMBER` | Query, Rules | Formats a number using your app number format settings by default. | `=FORMATNUMBER(1234.5, 2)` | `decimals`, `thousandsSeparator`, `decimalSeparator` |
+| `FV` | Query | Calculates future value of investment. | `=FV(0.05/12, 12, -100)` | — |
+| `FVSCHEDULE` | Query | Calculates future value of a principal using a schedule of varying interest rates. | `=FVSCHEDULE(1000, {0.05;0.06;0.07})` | — |
+| `HLOOKUP` | Query | Searches horizontally in first row and returns value. | `=HLOOKUP("key", A1:D10, 2, TRUE)` | — |
+| `IF` | Query, Rules | Returns one value if condition is TRUE, another if FALSE. | `=IF(amount<0, "Expense", "Income")` | — |
+| `IFERROR` | Query, Rules | Returns value if no error, otherwise returns alternative. | `=IFERROR(1/0, 0)` | — |
+| `IFNA` | Query, Rules | Returns value if not #N/A error, otherwise returns alternative. | `=IFNA(VLOOKUP("x", A1:B10, 2, FALSE), 0)` | — |
+| `IFS` | Query, Rules | Checks multiple conditions and returns corresponding values. | `=IFS(amount<0, "Expense", amount>0, "Income")` | Repeat `(condition, value)` pairs |
+| `INDEX` | Query | Returns value at specified row and column. | `=INDEX(A1:C10, 2, 3)` | — |
+| `INTEGER_TO_AMOUNT` | Query, Rules | Converts integer amount to decimal amount (e.g., 1234 -> 12.34). | `=INTEGER_TO_AMOUNT(1234)` | `decimal_places` (default: 2) |
+| `INT` | Rules | Rounds down to nearest integer. | `=INT(10.9)` | — |
+| `IPMT` | Query, Rules | Calculates the interest portion of a loan payment for a given period. | `=IPMT(0.05/12, 1, 60, 20000)` | — |
+| `IRR` | Query | Calculates internal rate of return. | `=IRR(A1:A12)` | — |
+| `ISEVEN` | Rules | Returns TRUE if number is even. | `=ISEVEN(10)` | — |
+| `ISODD` | Rules | Returns TRUE if number is odd. | `=ISODD(11)` | — |
+| `ISBLANK` | Query, Rules | Returns TRUE if value is blank. | `=ISBLANK(notes)` | — |
+| `ISERROR` | Query, Rules | Returns TRUE if value is any error. | `=ISERROR(1/0)` | — |
+| `ISLOGICAL` | Query, Rules | Returns TRUE if value is logical (TRUE/FALSE). | `=ISLOGICAL(TRUE())` | — |
+| `ISNA` | Query, Rules | Returns TRUE if value is #N/A error. | `=ISNA(NA())` | — |
+| `ISNUMBER` | Query, Rules | Returns TRUE if value is a number. | `=ISNUMBER(amount)` | — |
+| `ISOWEEKNUM` | Rules | Returns ISO week number. | `=ISOWEEKNUM(date)` | — |
+| `ISREF` | Query | Returns TRUE if value is a reference. | `=ISREF(A1)` | — |
+| `ISTEXT` | Query, Rules | Returns TRUE if value is text. | `=ISTEXT(notes)` | — |
+| `LEFT` | Query, Rules | Returns leftmost characters from text. | `=LEFT(imported_payee, 10)` | — |
+| `LEN` | Query, Rules | Returns length of text. | `=LEN(notes)` | — |
+| `LN` | Query | Returns the natural logarithm. | `=LN(10)` | — |
+| `LOG` | Query | Returns the logarithm to specified base. | `=LOG(100, 10)` | — |
+| `LOG10` | Query | Returns the base-10 logarithm. | `=LOG10(1000)` | — |
+| `LOOKUP` | Query | Looks up values in a vector or array. | `=LOOKUP("x", A1:A10)` | — |
+| `LOWER` | Query, Rules | Converts text to lowercase. | `=LOWER(notes)` | — |
+| `MATCH` | Query | Returns position of value in array. | `=MATCH("x", A1:A10, 0)` | — |
+| `MAX` | Query | Returns the maximum value. | `=MAX(1, 2, 3)` | Accepts more than 2 values |
+| `MAXA` | Query | Returns the maximum value, including text and logical values. | `=MAXA(1, TRUE, "2")` | Accepts more than 2 values |
+| `MEDIAN` | Query | Returns the median value. | `=MEDIAN(1, 2, 100)` | Accepts more than 2 values |
+| `MID` | Query, Rules | Returns substring from specified position. | `=MID(notes, 1, 10)` | — |
+| `MIN` | Query | Returns the minimum value. | `=MIN(1, 2, 3)` | Accepts more than 2 values |
+| `MINA` | Query | Returns the minimum value, including text and logical values. | `=MINA(1, TRUE, "2")` | Accepts more than 2 values |
+| `MIRR` | Query | Calculates the modified internal rate of return for a series of cash flows. | `=MIRR(A1:A12, 0.1, 0.12)` | — |
+| `MOD` | Query, Rules | Returns the remainder of division. | `=MOD(10, 3)` | — |
+| `MODE` | Query | Returns the most frequently occurring value. | `=MODE(1, 1, 2)` | Accepts more than 2 values |
+| `MONTH` | Query, Rules | Returns the month from a date. | `=MONTH(date)` | — |
+| `N` | Rules | Converts value to a number. | `=N(TRUE())` | — |
+| `NETWORKDAYS` | Query | Returns number of working days between dates. | `=NETWORKDAYS("2025-12-01", "2025-12-31")` | — |
+| `NOT` | Query, Rules | Reverses the logical value. | `=NOT(amount<0)` | — |
+| `NOW` | Query, Rules | Returns current date and time. | `=NOW()` | — |
+| `NPER` | Query, Rules | Calculates the number of payment periods for a loan or investment. | `=NPER(0.05/12, -200, 10000)` | — |
+| `NPV` | Query | Calculates net present value. | `=NPV(0.1, -1000, 200, 300)` | Accepts more than 2 values |
+| `OR` | Query, Rules | Returns TRUE if any argument is TRUE. | `=OR(amount<0, amount>0)` | Accepts more than 2 conditions |
+| `PERCENTILE` | Query | Returns the k-th percentile. | `=PERCENTILE(A1:A100, 0.9)` | — |
+| `PI` | Query | Returns the value of PI. | `=PI()` | — |
+| `PMT` | Query | Calculates payment for a loan. | `=PMT(0.05/12, 60, 10000)` | — |
+| `POWER` | Query, Rules | Returns base raised to the power of exponent. | `=POWER(2, 8)` | — |
+| `PPMT` | Query, Rules | Calculates the principal portion of a loan payment for a given period. | `=PPMT(0.05/12, 1, 60, 20000)` | — |
+| `PROPER` | Query, Rules | Capitalizes first letter of each word. | `=PROPER(notes)` | — |
+| `PRODUCT` | Query | Returns the product of all numbers. | `=PRODUCT(2, 3, 4)` | Accepts more than 2 values |
+| `PV` | Query | Calculates present value of investment. | `=PV(0.05/12, 12, -100)` | — |
+| `QUARTILE` | Query | Returns the quartile of a dataset. | `=QUARTILE(A1:A100, 1)` | — |
+| `QUERY` | Query | Execute a query and return the result. | `=QUERY("expenses")` | — |
+| `QUERY_COUNT` | Query | Execute a query and return the number of matching rows. | `=QUERY_COUNT("expenses")` | — |
+| `QUERY_EXTRACT_CATEGORIES` | Query | Determines which categories to include based on a named query's category filters; used as the `categories` argument in `BUDGET_QUERY`. | `=QUERY_EXTRACT_CATEGORIES("expenses")` | — |
+| `QUERY_EXTRACT_TIMEFRAME_END` | Query | Extracts the end month from a named query's date range; used as the `endMonth` argument in `BUDGET_QUERY`. | `=QUERY_EXTRACT_TIMEFRAME_END("expenses")` | — |
+| `QUERY_EXTRACT_TIMEFRAME_START` | Query | Extracts the start month from a named query's date range; used as the `startMonth` argument in `BUDGET_QUERY`. | `=QUERY_EXTRACT_TIMEFRAME_START("expenses")` | — |
+| `RANK` | Query | Returns the rank of a number in a list. | `=RANK(10, A1:A10, 0)` | — |
+| `RATE` | Query | Calculates interest rate per period. | `=RATE(60, -200, 10000)` | — |
+| `REPLACE` | Query, Rules | Replaces substring at specified position. | `=REPLACE(notes, 1, 5, "")` | — |
+| `REPT` | Query, Rules | Repeats text specified number of times. | `=REPT("*", 10)` | — |
+| `RIGHT` | Query, Rules | Returns rightmost characters from text. | `=RIGHT(imported_payee, 4)` | — |
+| `ROUND` | Query, Rules | Rounds a number to specified decimals. | `=ROUND(amount, 2)` | — |
+| `ROUNDDOWN` | Query, Rules | Rounds down to specified decimals. | `=ROUNDDOWN(amount, 0)` | — |
+| `ROUNDUP` | Query, Rules | Rounds up to specified decimals. | `=ROUNDUP(amount, 0)` | — |
+| `SEARCH` | Query, Rules | Finds text within text (case-insensitive, supports wildcards). | `=SEARCH("foo", notes)` | — |
+| `SIGN` | Rules | Returns -1 for negative, 0 for zero, 1 for positive. | `=SIGN(amount)` | — |
+| `SIN` | Query | Returns the sine of an angle. | `=SIN(1)` | — |
+| `SPLIT` | Rules | Splits text by space and returns part at index. | `=SPLIT(imported_payee, 0)` | — |
+| `SQRT` | Query, Rules | Returns the square root. | `=SQRT(9)` | — |
+| `STDEV` | Query | Returns the standard deviation of a sample. | `=STDEV(A1:A10)` | — |
+| `STDEVP` | Query | Returns the standard deviation of a population. | `=STDEVP(A1:A10)` | — |
+| `SUBSTITUTE` | Query, Rules | Replaces occurrences of text. | `=SUBSTITUTE(imported_payee, " 12345", "")` | — |
+| `SUM` | Query, Rules | Returns the sum of all numbers in a range. | `=SUM(1, 2, 3)` | Accepts more than 2 values |
+| `SUMIF` | Query | Sums cells that meet a criteria. | `=SUMIF(A1:A10, ">0", B1:B10)` | — |
+| `SUMIFS` | Query | Sums cells that meet multiple criteria. | `=SUMIFS(B1:B10, A1:A10, ">0", C1:C10, "X")` | Repeat `(range, criteria)` pairs |
+| `SUMPRODUCT` | Query | Multiplies corresponding elements and returns the sum. | `=SUMPRODUCT(A1:A10, B1:B10)` | Accepts more arrays |
+| `SUMSQ` | Query | Returns the sum of the squares. | `=SUMSQ(1, 2, 3)` | Accepts more than 2 values |
+| `SWITCH` | Query, Rules | Matches expression against values and returns corresponding result. | `=SWITCH(category_name, "Groceries", "Food", "Fuel", "Transport")` | Repeat `(value, result)` pairs; default supported |
+| `T` | Rules | Returns text if value is text, empty string otherwise. | `=T(notes)` | — |
+| `TAN` | Query | Returns the tangent of an angle. | `=TAN(1)` | — |
+| `TEXT` | Query, Rules | Converts number to text with format. | `=TEXT(date, "MMMM yyyy")` | — |
+| `TODAY` | Query, Rules | Returns current date. | `=TODAY()` | — |
+| `TRIM` | Query, Rules | Removes extra spaces from text. | `=TRIM(notes)` | — |
+| `TRUNC` | Rules | Truncates number to specified decimals. | `=TRUNC(amount, 0)` | — |
+| `TRUE` | Query, Rules | Returns the logical value TRUE. | `=TRUE()` | — |
+| `UPPER` | Query, Rules | Converts text to uppercase. | `=UPPER(notes)` | — |
+| `VALUE` | Rules | Converts text to a number. | `=VALUE("123.45")` | — |
+| `VAR` | Query | Returns the variance of a sample. | `=VAR(A1:A10)` | — |
+| `VARP` | Query | Returns the variance of a population. | `=VARP(A1:A10)` | — |
+| `VLOOKUP` | Query | Searches vertically in first column and returns value. | `=VLOOKUP("key", A1:D10, 2, TRUE)` | — |
+| `WEEKDAY` | Query, Rules | Returns day of week (1-7). | `=WEEKDAY(date, 1)` | — |
+| `WEEKNUM` | Query, Rules | Returns week number of year. | `=WEEKNUM(date, 1)` | — |
+| `XNPV` | Query | Calculates net present value for cash flows on irregular (dated) intervals. | `=XNPV(0.1, A1:A5, B1:B5)` | — |
+| `XOR` | Query, Rules | Returns TRUE if odd number of arguments are TRUE. | `=XOR(TRUE(), FALSE())` | Accepts more than 2 conditions |
+| `YEAR` | Query, Rules | Returns the year from a date. | `=YEAR(date)` | — |
### Formatting numbers and currency
@@ -230,7 +230,7 @@ Example:
```
:::tip
-In rule formulas, `BALANCE_OF` instead returns the running balance **at a specific transaction**, in cents — see [Rule formulas](#rule-formulas) below.
+In rule formulas, `BALANCE_OF` instead returns the running balance **at a specific transaction** — see [Rule formulas](#rule-formulas) below.
:::
### Define a query
@@ -326,14 +326,12 @@ Rule formulas evaluate with named variables from the transaction context, includ
- `today` — Current date in YYYY-MM-DD format (e.g., `"2025-12-19"`)
- `date` — Transaction date in YYYY-MM-DD format (e.g., `"2025-01-15"`)
-**Numeric variables (stored in cents):**
+**Numeric variables:**
-- `amount` — Transaction amount as an integer in cents (e.g., `12345` represents $123.45)
+- `amount` — Transaction amount (e.g., `123.45`)
- Positive for income, negative for expenses
- - To convert to dollars: `=amount / 100`
-- `balance` — Account balance after this transaction, as an integer in cents
- - Represents the running balance at this transaction
- - To convert to dollars: `=balance / 100`
+- `balance` — Account balance at this transaction, excluding the transaction itself
+- `parent_amount` — Amount of the parent transaction, available when a rule splits a transaction
**Text variables:**
@@ -348,12 +346,8 @@ Rule formulas evaluate with named variables from the transaction context, includ
- `cleared` — Whether transaction is cleared (`TRUE` or `FALSE`)
- `reconciled` — Whether transaction is reconciled (`TRUE` or `FALSE`)
-:::caution Cents in, dollars out
-Numbers going **into** a formula and numbers coming **out** of one use different units.
-
-The `amount` and `balance` variables hand you integer cents, but a number your formula produces is read as **dollars** and converted to cents when Actual stores it. So a formula of `=500 + 250` sets the amount to $750.00, not $7.50.
-
-When you calculate with `amount` or `balance`, divide by 100 first so both sides are in dollars. For example, `=amount / 100 * 1.05` adds 5% to the transaction amount, while `=amount * 1.05` gives a result 100 times too large.
+:::caution
+Rule formulas used to work in cents, so they had to divide by 100. Formulas you saved back then are not updated for you, and they now produce a result 100 times too small. Open each one and remove the `/ 100`: a formula that read `=amount / 100 * 1.05` becomes `=amount * 1.05`. The same goes for uses of the `INTEGER_TO_AMOUNT` and `AMOUNT_TO_INTEGER` functions, your formula outputs may be off by a factor of 100 for each use. Evaluate your personal formulas as likely you no longer need to use these functions.
:::
### Available functions
@@ -365,11 +359,10 @@ When you calculate with `amount` or `balance`, divide by 100 first so both sides
=BALANCE_OF("Checking")
```
-- `BALANCE_OF("…")` — Running balance for another account, in **cents**, using the same cutoff as `balance` (same `date`, `sort_order`, and `id` ordering as the current transaction).
+- `BALANCE_OF("…")` — Running balance for another account, using the same cutoff as `balance` (same `date`, `sort_order`, and `id` ordering as the current transaction).
- Pass a **quoted account id** (matches an account id in your budget) for a deterministic result, or a **quoted account name** for an exact name match. If the account name is ambiguous (duplicates), the first match is used.
- If the account is not found, the value is **0**.
- For the **current** transaction’s account, use the `balance` variable instead of `BALANCE_OF`.
-- Returns an integer in cents. For the amount in dollars, divide by 100 or `=INTEGER_TO_AMOUNT(BALANCE_OF("Checking"))`.
- `BALANCE_OF` is also available in Formula cards, where it returns the account's current balance instead — see [Account balances with `BALANCE_OF("name")`](#account-balances-with-balance_ofname) above.
**Loan payment functions (`IPMT`, `PPMT`, `NPER`, `CUMIPMT`, `CUMPRINC`):**
@@ -382,7 +375,7 @@ If you record a loan (mortgage, auto loan, etc.) payment as a single transaction
This computes the interest portion of the payment for the month of the current transaction, for a 30-year (360-month) loan that started 2024-01-01 at 5% annual interest on a $300,000 principal. Swap `IPMT` for `PPMT` to get the principal portion instead, or use `CUMIPMT`/`CUMPRINC` with a `start_period` of `1` and that same period as `end_period` to get interest/principal paid to date.
-Write the principal in dollars (`-300000`), not cents. These functions return their result in the same unit you pass in, and Actual expects a numeric formula result in dollars — see [Cents in, dollars out](#available-variables) above.
+These functions return their result in the same units you pass in, so write the principal as `-300000`.
### Result types
@@ -392,5 +385,3 @@ When a rule runs, Actual converts the formula result to the field type:
- **date fields**: must produce a valid date
- **boolean fields**: `TRUE`/`FALSE` (or a string that equals `"true"`/`"false"`)
- **string fields**: converted with `String(...)`
-
-Number fields receive the result in dollars and store it in cents — see [Cents in, dollars out](#available-variables) above.
diff --git a/packages/loot-core/src/server/rules/action.ts b/packages/loot-core/src/server/rules/action.ts
index 4882abf977..f3b96858d2 100644
--- a/packages/loot-core/src/server/rules/action.ts
+++ b/packages/loot-core/src/server/rules/action.ts
@@ -12,7 +12,7 @@ import {
} from '#shared/formulas/customFunctions';
import { currentDay, format, parseDate } from '#shared/months';
import { FIELD_TYPES } from '#shared/rules';
-import { amountToInteger } from '#shared/util';
+import { amountToInteger, integerToAmount } from '#shared/util';
import { assert } from './rule-utils';
@@ -34,6 +34,14 @@ const ACTION_OPS = [
] as const;
type ActionOperator = (typeof ACTION_OPS)[number];
+// Transaction fields stored as integers that a formula reads as the amounts
+// shown in the app.
+const MONETARY_FORMULA_VARIABLES: ReadonlySet<string> = new Set([
+ 'amount',
+ 'balance',
+ 'parent_amount',
+]);
+
export class Action {
field;
op: ActionOperator;
@@ -113,7 +121,7 @@ export class Action {
const error = `Formula for "${this.field}" must produce a numeric value. Got: ${JSON.stringify(result)}`;
object._ruleErrors.push(error);
} else {
- object[this.field] = numValue;
+ object[this.field] = amountToInteger(numValue);
}
break;
}
@@ -220,7 +228,7 @@ export class Action {
`Formula for split amount must produce a numeric value. Got: ${JSON.stringify(result)}`,
);
} else {
- object.amount = numValue;
+ object.amount = amountToInteger(numValue);
}
} catch (err) {
object._ruleErrors.push(
@@ -291,6 +299,12 @@ export class Action {
return variables;
}
+ /**
+ * Evaluate a formula against a transaction. Monetary values are converted on
+ * the way in, so the formula both reads and returns the amounts a user sees
+ * in the app rather than the integers the transaction stores. Callers writing
+ * the result back to an amount field convert it with `amountToInteger`.
+ */
executeFormulaSync(
formula: string,
transaction: Partial<TransactionForRules>,
@@ -302,13 +316,18 @@ export class Action {
}
try {
+ // The prefetched balances are integers; formulas work in amounts.
+ const balanceOfPrefetch = new Map<string, number>();
+ for (const [key, integerAmount] of transaction['_balanceOfPrefetched'] ??
+ []) {
+ balanceOfPrefetch.set(key, integerToAmount(integerAmount));
+ }
+
hfInstance = HyperFormula.buildEmpty({
licenseKey: 'gpl-v3',
language: 'enUS',
dateFormats: ['DD/MM/YYYY', 'YYYY-MM-DD', 'YYYY/MM/DD'],
- context: {
- balanceOfPrefetch: transaction['_balanceOfPrefetched'] ?? new Map(),
- },
+ context: { balanceOfPrefetch },
});
const sheetName = hfInstance.addSheet('Sheet1');
@@ -333,15 +352,22 @@ export class Action {
if (key === '_balanceOfPrefetched') {
continue;
}
+ const rawValue = fieldValues[key];
let cellValue: string | number | boolean;
if (
- fieldValues[key] === undefined ||
- fieldValues[key] === null ||
- typeof fieldValues[key] === 'object'
+ rawValue === undefined ||
+ rawValue === null ||
+ typeof rawValue === 'object'
) {
cellValue = '';
+ } else if (
+ MONETARY_FORMULA_VARIABLES.has(key) &&
+ typeof rawValue === 'number'
+ ) {
+ // Formulas work in amounts; the transaction stores integers.
+ cellValue = integerToAmount(rawValue);
} else {
- cellValue = fieldValues[key];
+ cellValue = rawValue;
}
// Parent text is data, even when it looks like a spreadsheet formula,
// date or number. The apostrophe is HyperFormula's literal-text escape.
@@ -361,10 +387,6 @@ export class Action {
throw new Error(`Formula error: ${cellValue.message}`);
}
- if (typeof cellValue === 'number') {
- return amountToInteger(Math.round(cellValue * 100) / 100);
- }
-
return cellValue;
} catch (err) {
logger.error('Formula execution error:', err);
diff --git a/packages/loot-core/src/server/rules/formula-action-integration.test.ts b/packages/loot-core/src/server/rules/formula-action-integration.test.ts
index 83cf3b5122..9e95fe440a 100644
--- a/packages/loot-core/src/server/rules/formula-action-integration.test.ts
+++ b/packages/loot-core/src/server/rules/formula-action-integration.test.ts
@@ -50,7 +50,7 @@ describe('Formula Rule Actions - Integration Tests', () => {
notes: '',
});
- expect(transaction.notes).toBe('Interest: $5,000.00');
+ expect(transaction.notes).toBe('Interest: $50.00');
});
it('should use nested IF statements with transaction fields', async () => {
@@ -68,7 +68,7 @@ describe('Formula Rule Actions - Integration Tests', () => {
value: null,
options: {
formula:
- '=IF(amount > 0, "Income", IF(ABS(amount) > 10000, "Large Expense", IF(ABS(amount) > 5000, "Medium Expense", "Small Expense")))',
+ '=IF(amount > 0, "Income", IF(ABS(amount) > 100, "Large Expense", IF(ABS(amount) > 50, "Medium Expense", "Small Expense")))',
},
},
],
@@ -133,7 +133,7 @@ describe('Formula Rule Actions - Integration Tests', () => {
value: null,
options: {
formula:
- '=CONCATENATE(UPPER(payee_name), " - ", FORMATCURRENCY(amount / 100), " on ", TEXT(date, "MM/DD/YYYY"))',
+ '=CONCATENATE(UPPER(payee_name), " - ", FORMATCURRENCY(amount), " on ", TEXT(date, "MM/DD/YYYY"))',
},
},
],
@@ -257,7 +257,7 @@ describe('Formula Rule Actions - Integration Tests', () => {
value: null,
options: {
formula:
- '=CONCATENATE("Split: ", FORMATCURRENCY(ROUND((amount / 100) * 0.333, 2)))',
+ '=CONCATENATE("Split: ", FORMATCURRENCY(ROUND(amount * 0.333, 2)))',
},
},
],
@@ -286,7 +286,7 @@ describe('Formula Rule Actions - Integration Tests', () => {
value: null,
options: {
formula:
- '=CONCATENATE("Fee: ", FORMATCURRENCY(MAX((ABS(amount) / 100) * 0.01, 5)))',
+ '=CONCATENATE("Fee: ", FORMATCURRENCY(MAX(ABS(amount) * 0.01, 5)))',
},
},
],
@@ -317,7 +317,7 @@ describe('Formula Rule Actions - Integration Tests', () => {
value: null,
options: {
formula:
- '=CONCATENATE("Rounded: ", FORMATCURRENCY(CEILING(amount / 100, -1)))',
+ '=CONCATENATE("Rounded: ", FORMATCURRENCY(CEILING(amount, -1)))',
},
},
],
@@ -362,7 +362,7 @@ describe('Formula Rule Actions - Integration Tests', () => {
notes: '',
});
- expect(transaction.notes).toBe('Square root: 100.00');
+ expect(transaction.notes).toBe('Square root: 10.00');
});
});
@@ -509,7 +509,7 @@ describe('Formula Rule Actions - Integration Tests', () => {
value: null,
options: {
formula:
- '=IF(AND(amount < 0, ABS(amount) > 10000), "Large Expense", IF(OR(amount > 0, ABS(amount) < 1000), "Small Transaction", "Medium Transaction"))',
+ '=IF(AND(amount < 0, ABS(amount) > 100), "Large Expense", IF(OR(amount > 0, ABS(amount) < 10), "Small Transaction", "Medium Transaction"))',
},
},
],
@@ -630,8 +630,7 @@ describe('Formula Rule Actions - Integration Tests', () => {
field: 'notes',
value: null,
options: {
- formula:
- '=CONCATENATE("Amount: ", FORMATNUMBER(amount / 100, 2))',
+ formula: '=CONCATENATE("Amount: ", FORMATNUMBER(amount, 2))',
},
},
],
@@ -660,7 +659,7 @@ describe('Formula Rule Actions - Integration Tests', () => {
field: 'notes',
value: null,
options: {
- formula: '=FORMATCURRENCY(amount / 100, "€", 2)',
+ formula: '=FORMATCURRENCY(amount, "€", 2)',
},
},
],
@@ -688,7 +687,7 @@ describe('Formula Rule Actions - Integration Tests', () => {
field: 'notes',
value: null,
options: {
- formula: '=FORMATCURRENCY(amount / 100, "€", 2, ".", ",")',
+ formula: '=FORMATCURRENCY(amount, "€", 2, ".", ",")',
},
},
],
@@ -718,7 +717,7 @@ describe('Formula Rule Actions - Integration Tests', () => {
field: 'notes',
value: null,
options: {
- formula: '=FORMATNUMBER(amount / 100, 0)',
+ formula: '=FORMATNUMBER(amount, 0)',
},
},
],
@@ -751,7 +750,7 @@ describe('Formula Rule Actions - Integration Tests', () => {
value: null,
options: {
formula:
- '=CONCATENATE("Payment: ", FORMATCURRENCY(amount / 100), " | Principal: ", FORMATCURRENCY((amount / 100) * 0.8), " | Interest: ", FORMATCURRENCY((amount / 100) * 0.2), " | Month: ", MONTH(date))',
+ '=CONCATENATE("Payment: ", FORMATCURRENCY(amount), " | Principal: ", FORMATCURRENCY(amount * 0.8), " | Interest: ", FORMATCURRENCY(amount * 0.2), " | Month: ", MONTH(date))',
},
},
],
@@ -784,7 +783,7 @@ describe('Formula Rule Actions - Integration Tests', () => {
value: null,
options: {
formula:
- '=CONCATENATE(UPPER(LEFT(imported_payee, 7)), " - ", IF(WEEKDAY(date) = 1, "Weekend", "Weekday"), " - ", FORMATCURRENCY(ABS(amount) / 100), " - ", MONTH(date), "/", DAY(date))',
+ '=CONCATENATE(UPPER(LEFT(imported_payee, 7)), " - ", IF(WEEKDAY(date) = 1, "Weekend", "Weekday"), " - ", FORMATCURRENCY(ABS(amount)), " - ", MONTH(date), "/", DAY(date))',
},
},
],
@@ -849,7 +848,7 @@ describe('Formula Rule Actions - Integration Tests', () => {
value: null,
options: {
formula:
- '=CONCATENATE("Merchant: ", payee_name, CHAR(10), "Amount: ", FORMATCURRENCY(amount / 100), CHAR(10), "Date: ", YEAR(date), "-", MONTH(date), "-", DAY(date))',
+ '=CONCATENATE("Merchant: ", payee_name, CHAR(10), "Amount: ", FORMATCURRENCY(amount), CHAR(10), "Date: ", YEAR(date), "-", MONTH(date), "-", DAY(date))',
},
},
],
@@ -883,7 +882,7 @@ describe('Formula Rule Actions - Integration Tests', () => {
value: null,
options: {
formula:
- '=CONCATENATE("Transaction Summary", CHAR(10), "Amount: ", FORMATCURRENCY(amount / 100), CHAR(10), "Tax (10%): ", FORMATCURRENCY((amount / 100) * 0.1), CHAR(10), "Total: ", FORMATCURRENCY((amount / 100) * 1.1))',
+ '=CONCATENATE("Transaction Summary", CHAR(10), "Amount: ", FORMATCURRENCY(amount), CHAR(10), "Tax (10%): ", FORMATCURRENCY(amount * 0.1), CHAR(10), "Total: ", FORMATCURRENCY(amount * 1.1))',
},
},
],
@@ -1108,7 +1107,7 @@ describe('Formula Rule Actions - Integration Tests', () => {
value: null,
options: {
formula:
- '=CONCATENATE("Compound: ", FORMATCURRENCY((amount / 100) * POWER(1.05, 12)))',
+ '=CONCATENATE("Compound: ", FORMATCURRENCY(amount * POWER(1.05, 12)))',
},
},
],
diff --git a/packages/loot-core/src/server/rules/formula-action.test.ts b/packages/loot-core/src/server/rules/formula-action.test.ts
index 0967932dfa..dcb2fa689a 100644
--- a/packages/loot-core/src/server/rules/formula-action.test.ts
+++ b/packages/loot-core/src/server/rules/formula-action.test.ts
@@ -25,15 +25,38 @@ describe('Formula-based rule actions', () => {
const transaction: Partial<TransactionForRules> = { amount: 500 };
const result = action.executeFormulaSync('=100 + 200', transaction);
- expect(result).toBe(30000);
+ expect(result).toBe(300);
});
it('should use transaction field variables', () => {
const action = new Action('set', 'notes', null, {});
const transaction = { amount: 5000 };
- const result = action.executeFormulaSync('=amount / 100', transaction);
+ const result = action.executeFormulaSync('=amount', transaction);
- expect(result).toBe(5000);
+ expect(result).toBe(50);
+ });
+
+ it('should provide amount and parent_amount as amounts, not integers', () => {
+ const action = new Action('set', 'notes', null, {});
+ const transaction: Partial<TransactionForRules> = {
+ amount: -4567,
+ parent_amount: 20000,
+ };
+
+ expect(action.executeFormulaSync('=amount', transaction)).toBe(-45.67);
+ expect(action.executeFormulaSync('=parent_amount * 0.5', transaction)).toBe(
+ 100,
+ );
+ });
+
+ it('should leave non-monetary numeric fields alone', () => {
+ const action = new Action('set', 'notes', null, {});
+ const transaction: Partial<TransactionForRules> = {
+ amount: 100,
+ sort_order: 1234,
+ };
+
+ expect(action.executeFormulaSync('=sort_order', transaction)).toBe(1234);
});
it('should support IF function with transaction fields', () => {
@@ -126,7 +149,7 @@ describe('Formula-based rule actions', () => {
};
const result = action.executeFormulaSync('=balance * 2', transaction);
- expect(result).toBe(300000);
+ expect(result).toBe(30);
});
it('should support BALANCE_OF with prefetched map', () => {
@@ -142,13 +165,13 @@ describe('Formula-based rule actions', () => {
'=BALANCE_OF("Savings") + 100',
transaction,
);
- expect(byName).toBe(5010000);
+ expect(byName).toBe(600);
const byId = action.executeFormulaSync(
'=BALANCE_OF("550e8400-e29b-41d4-a716-446655440000")',
transaction,
);
- expect(byId).toBe(120000);
+ expect(byId).toBe(12);
});
it('should return 0 for BALANCE_OF when literal missing from prefetch map', () => {
@@ -175,6 +198,26 @@ describe('Formula-based rule actions', () => {
expect(transaction.amount).toBe(75000);
});
+ it('should round-trip the amount field through a formula', () => {
+ const action = new Action('set', 'amount', null, { formula: '=amount' });
+
+ const transaction = { amount: 12345 };
+ action.exec(transaction);
+
+ expect(transaction.amount).toBe(12345);
+ });
+
+ it('should apply a percentage to the amount field', () => {
+ const action = new Action('set', 'amount', null, {
+ formula: '=amount * 1.05',
+ });
+
+ const transaction = { amount: -10000 };
+ action.exec(transaction);
+
+ expect(transaction.amount).toBe(-10500);
+ });
+
it('should execute formula and convert to string type', () => {
const action = new Action('set', 'notes', null, {
formula: '=UPPER("hello")',
@@ -222,8 +265,9 @@ describe('Formula-based rule actions', () => {
const transaction = { notes: 'original' };
action.exec(transaction);
- // Should convert number to string
- expect(transaction.notes).toBe('75000');
+ // Text fields get the number the formula produced, not an amount scaled
+ // up for storage
+ expect(transaction.notes).toBe('750');
});
it('should format numbers with thousands separators using FORMATNUMBER', () => {
diff --git a/packages/loot-core/src/server/rules/index.test.ts b/packages/loot-core/src/server/rules/index.test.ts
index 2ec1219e7a..10fb601864 100644
--- a/packages/loot-core/src/server/rules/index.test.ts
+++ b/packages/loot-core/src/server/rules/index.test.ts
@@ -943,7 +943,7 @@ describe('Rule', () => {
options: {
splitIndex: 1,
method: 'formula',
- formula: '=INTEGER_TO_AMOUNT(parent_amount) * 0.5',
+ formula: '=parent_amount * 0.5',
},
},
{
@@ -958,7 +958,7 @@ describe('Rule', () => {
],
});
- // Fixed amount 10000 (100 in formula = $100.00 = 10000 cents), remainder = 10000
+ // Half of the $200.00 parent is $100.00, remainder = $100.00
expect(
rule.exec({ imported_payee: 'James', amount: 20000 }),
).toMatchObject({
diff --git a/packages/loot-core/src/server/rules/split-parent-context.test.ts b/packages/loot-core/src/server/rules/split-parent-context.test.ts
index 1a65f38937..660e9ed781 100644
--- a/packages/loot-core/src/server/rules/split-parent-context.test.ts
+++ b/packages/loot-core/src/server/rules/split-parent-context.test.ts
@@ -43,10 +43,8 @@ const parent = {
};
describe('split parent formula context', () => {
- test('keeps parent_amount in cents', () => {
- expect(
- splitRule('=INTEGER_TO_AMOUNT(parent_amount) / 2').exec(parent),
- ).toMatchObject({
+ test('reads parent_amount as an amount', () => {
+ expect(splitRule('=parent_amount / 2').exec(parent)).toMatchObject({
subtransactions: [{ amount: -1500 }, { amount: -1500 }],
});
});
diff --git a/packages/loot-core/src/server/transactions/transaction-rules.ts b/packages/loot-core/src/server/transactions/transaction-rules.ts
index 26af124d99..0f9a3818b2 100644
--- a/packages/loot-core/src/server/transactions/transaction-rules.ts
+++ b/packages/loot-core/src/server/transactions/transaction-rules.ts
@@ -1053,7 +1053,10 @@ export type TransactionForRules = TransactionEntity & {
parent_imported_payee?: string;
parent_payee?: string;
parent_account?: string;
- /** Prefetched cent balances for BALANCE_OF("…") in rule formulas; cleared in finalize */
+ /**
+ * Prefetched integer balances for BALANCE_OF("…") in rule formulas; converted
+ * to amounts at the formula boundary in executeFormulaSync, cleared in finalize
+ */
_balanceOfPrefetched?: Map<string, number>;
};
diff --git a/upcoming-release-notes/rule-formula-amount-units.md b/upcoming-release-notes/rule-formula-amount-units.md
new file mode 100644
index 0000000000..1520ae22d3
--- /dev/null
+++ b/upcoming-release-notes/rule-formula-amount-units.md
@@ -0,0 +1,6 @@
+---
+category: Enhancements
+authors: [youngcw]
+---
+
+Use everyday amounts instead of cents in rule formulas