From 4674916d3e0691ed3f8ac94ef64df29c4974c5c2 Mon Sep 17 00:00:00 2001 From: Stephen Brown II Date: Wed, 4 Feb 2026 13:36:55 -0600 Subject: [PATCH] Avoid negative zero in budget summary amounts (#6843) --- .../envelope/budgetsummary/TotalsList.tsx | 46 +++++++++++++------ upcoming-release-notes/6843.md | 6 +++ 2 files changed, 39 insertions(+), 13 deletions(-) create mode 100644 upcoming-release-notes/6843.md diff --git a/packages/desktop-client/src/components/budget/envelope/budgetsummary/TotalsList.tsx b/packages/desktop-client/src/components/budget/envelope/budgetsummary/TotalsList.tsx index db8ace2e99..8c8f4ccc84 100644 --- a/packages/desktop-client/src/components/budget/envelope/budgetsummary/TotalsList.tsx +++ b/packages/desktop-client/src/components/budget/envelope/budgetsummary/TotalsList.tsx @@ -9,9 +9,36 @@ import { View } from '@actual-app/components/view'; import { EnvelopeCellValue } from '@desktop-client/components/budget/envelope/EnvelopeBudgetComponents'; import { CellValueText } from '@desktop-client/components/spreadsheet/CellValue'; -import { useFormat } from '@desktop-client/hooks/useFormat'; +import { useFormat, type FormatType } from '@desktop-client/hooks/useFormat'; import { envelopeBudget } from '@desktop-client/spreadsheet/bindings'; +/** + * Creates a formatter that displays values with explicit +/- signs. + * Uses Math.abs to avoid double-negative display (e.g., "--$0.00"). + * + * @param format - The format function from useFormat hook + * @param invert - If true, shows '-' for positive and '+' for negative + */ +function makeSignedFormatter( + format: ReturnType, + invert = false, +) { + return (value: number, type?: FormatType) => { + const v = format(Math.abs(value), type); + if (value === 0) { + return '-' + v; + } + const isPositive = value > 0; + return invert + ? isPositive + ? '-' + v + : '+' + v + : isPositive + ? '+' + v + : '-' + v; + }; +} + type TotalsListProps = { prevMonthName: string; style?: CSSProperties; @@ -19,6 +46,8 @@ type TotalsListProps = { export function TotalsList({ prevMonthName, style }: TotalsListProps) { const format = useFormat(); + const signedFormatter = makeSignedFormatter(format); + const invertedSignedFormatter = makeSignedFormatter(format, true); return ( { - const v = format(value, type); - return value > 0 ? '+' + v : value === 0 ? '-' + v : v; - }} + formatter={signedFormatter} /> )} @@ -94,10 +120,7 @@ export function TotalsList({ prevMonthName, style }: TotalsListProps) { { - const v = format(value, type); - return value > 0 ? '+' + v : value === 0 ? '-' + v : v; - }} + formatter={signedFormatter} /> )} @@ -110,10 +133,7 @@ export function TotalsList({ prevMonthName, style }: TotalsListProps) { { - const v = format(Math.abs(value), type); - return value >= 0 ? '-' + v : '+' + v; - }} + formatter={invertedSignedFormatter} /> )} diff --git a/upcoming-release-notes/6843.md b/upcoming-release-notes/6843.md new file mode 100644 index 0000000000..a5e07055ba --- /dev/null +++ b/upcoming-release-notes/6843.md @@ -0,0 +1,6 @@ +--- +category: Bugfixes +authors: [StephenBrown2] +--- + +Fix double negative sign in budget summary amounts