Avoid negative zero in budget summary amounts (#6843)

This commit is contained in:
Stephen Brown II
2026-02-04 13:36:55 -06:00
committed by GitHub
parent 5388a115e9
commit 4674916d3e
2 changed files with 39 additions and 13 deletions

View File

@@ -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>

View File

@@ -0,0 +1,6 @@
---
category: Bugfixes
authors: [StephenBrown2]
---
Fix double negative sign in budget summary amounts