mirror of
https://github.com/actualbudget/actual.git
synced 2026-03-09 03:32:54 -05:00
Avoid negative zero in budget summary amounts (#6843)
This commit is contained in:
@@ -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>
|
||||
|
||||
6
upcoming-release-notes/6843.md
Normal file
6
upcoming-release-notes/6843.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
category: Bugfixes
|
||||
authors: [StephenBrown2]
|
||||
---
|
||||
|
||||
Fix double negative sign in budget summary amounts
|
||||
Reference in New Issue
Block a user