Skip to content

A local-first personal finance app

Avoid negative zero in budget summary amounts (#6843)

Stephen Brown II4674916d3e06
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<typeof useFormat>,
+ 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 (
<View
style={{
@@ -78,10 +107,7 @@ export function TotalsList({ prevMonthName, style }: TotalsListProps) {
<CellValueText
{...props}
style={{ fontWeight: 600 }}
- formatter={(value, type) => {
- const v = format(value, type);
- return value > 0 ? '+' + v : value === 0 ? '-' + v : v;
- }}
+ formatter={signedFormatter}
/>
)}
</EnvelopeCellValue>
@@ -94,10 +120,7 @@ export function TotalsList({ prevMonthName, style }: TotalsListProps) {
<CellValueText
{...props}
style={{ fontWeight: 600 }}
- formatter={(value, type) => {
- const v = format(value, type);
- return value > 0 ? '+' + v : value === 0 ? '-' + v : v;
- }}
+ formatter={signedFormatter}
/>
)}
</EnvelopeCellValue>
@@ -110,10 +133,7 @@ export function TotalsList({ prevMonthName, style }: TotalsListProps) {
<CellValueText
{...props}
style={{ fontWeight: 600 }}
- formatter={(value, type) => {
- const v = format(Math.abs(value), type);
- return value >= 0 ? '-' + v : '+' + v;
- }}
+ formatter={invertedSignedFormatter}
/>
)}
</EnvelopeCellValue>
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