[GH-ISSUE #7213] [Bug] fixed() function in spreadsheet formulas should return number not string #44671

Closed
opened 2026-04-26 06:27:05 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @mango766 on GitHub (Mar 16, 2026).
Original GitHub issue: https://github.com/actualbudget/actual/issues/7213

Issue Description

The fixed(number, decimals) function is supposed to be used in spreadsheet formulas (via HyperFormula) to format numbers with a fixed number of decimal places. However, it currently returns a string instead of a number because Number.toFixed() always returns a string.

This causes type mismatches when the result is used in further calculations within formulas.

Expected Behavior

When FIXED(3.14159, 2) is called in a spreadsheet formula, it should return a number like 3.14 that can be safely used in subsequent calculations.

Actual Behavior

The function returns the string "3.14" which then requires manual type conversion or causes issues when used in formulas expecting numeric values.

Affected Code

The issue is in packages/loot-core/src/server/rules/customFunctions.ts line 25:

return Number(number).toFixed(decimals);

This should convert the result back to a number:

return Number(Number(number).toFixed(decimals));

Related code in packages/loot-core/src/server/rules/handlebars-helpers.ts line 77 has the same pattern, but since it's a Handlebars helper (not HyperFormula), the string return is acceptable there.

Impact

Users who try to use the FIXED() function in formulas may experience unexpected behavior when the result is used in further calculations.

Steps to Reproduce

  1. Create a rule with a formula action using FIXED(amount, 2)
  2. Use that result in another calculation within the same formula

The result will be a string that may need manual conversion back to a number.

Suggested Fix

Simply wrap the toFixed call with Number() to return a numeric value instead of a string.

Originally created by @mango766 on GitHub (Mar 16, 2026). Original GitHub issue: https://github.com/actualbudget/actual/issues/7213 ## Issue Description The `fixed(number, decimals)` function is supposed to be used in spreadsheet formulas (via HyperFormula) to format numbers with a fixed number of decimal places. However, it currently returns a string instead of a number because `Number.toFixed()` always returns a string. This causes type mismatches when the result is used in further calculations within formulas. ## Expected Behavior When `FIXED(3.14159, 2)` is called in a spreadsheet formula, it should return a number like `3.14` that can be safely used in subsequent calculations. ## Actual Behavior The function returns the string `"3.14"` which then requires manual type conversion or causes issues when used in formulas expecting numeric values. ## Affected Code The issue is in `packages/loot-core/src/server/rules/customFunctions.ts` line 25: ```typescript return Number(number).toFixed(decimals); ``` This should convert the result back to a number: ```typescript return Number(Number(number).toFixed(decimals)); ``` Related code in `packages/loot-core/src/server/rules/handlebars-helpers.ts` line 77 has the same pattern, but since it's a Handlebars helper (not HyperFormula), the string return is acceptable there. ## Impact Users who try to use the `FIXED()` function in formulas may experience unexpected behavior when the result is used in further calculations. ## Steps to Reproduce 1. Create a rule with a formula action using `FIXED(amount, 2)` 2. Use that result in another calculation within the same formula The result will be a string that may need manual conversion back to a number. ## Suggested Fix Simply wrap the toFixed call with Number() to return a numeric value instead of a string.
Author
Owner

@youngcw commented on GitHub (Mar 16, 2026):

Please use the dedicated feedback ticket for the formula feature

<!-- gh-comment-id:4070371608 --> @youngcw commented on GitHub (Mar 16, 2026): Please use the dedicated feedback ticket for the formula feature
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/actual#44671