feat: show full decimals while editing (#5808)

* show full decimals while editing

* add changes

* handle null
This commit is contained in:
Çağdaş Şenel
2025-10-05 15:23:04 +02:00
committed by GitHub
parent cc2e329e8e
commit e1c2f0a181
4 changed files with 34 additions and 3 deletions

View File

@@ -57,6 +57,7 @@ import {
} from 'loot-core/shared/transactions';
import {
amountToCurrency,
currencyToAmount,
type IntegerAmount,
integerToCurrency,
titleFirst,
@@ -1591,6 +1592,10 @@ const Transaction = memo(function Transaction({
exposed={focusedField === 'debit'}
focused={focusedField === 'debit'}
value={debit === '' && credit === '' ? amountToCurrency(0) : debit}
formatter={value =>
// reformat value so since we might have kept decimals
value ? amountToCurrency(currencyToAmount(value) || 0) : ''
}
valueStyle={valueStyle}
textAlign="right"
title={debit}
@@ -1618,6 +1623,10 @@ const Transaction = memo(function Transaction({
exposed={focusedField === 'credit'}
focused={focusedField === 'credit'}
value={credit}
formatter={value =>
// reformat value so since we might have kept decimals
value ? amountToCurrency(currencyToAmount(value) || 0) : ''
}
valueStyle={valueStyle}
textAlign="right"
title={credit}

View File

@@ -5,7 +5,7 @@ import { currentDay } from 'loot-core/shared/months';
import {
amountToInteger,
type CurrencyAmount,
integerToCurrency,
integerToCurrencyWithDecimal,
} from 'loot-core/shared/util';
import {
type AccountEntity,
@@ -58,11 +58,12 @@ export function serializeTransaction(
date = null as unknown as string;
}
// Convert with decimals here so the value doesn't lose decimals and formatter will show or hide them.
return {
...transaction,
date,
debit: debit != null ? integerToCurrency(debit) : '',
credit: credit != null ? integerToCurrency(credit) : '',
debit: debit != null ? integerToCurrencyWithDecimal(debit) : '',
credit: credit != null ? integerToCurrencyWithDecimal(credit) : '',
};
}

View File

@@ -430,6 +430,21 @@ export function integerToCurrency(
return formatter.format(amount);
}
export function integerToCurrencyWithDecimal(integerAmount: IntegerAmount) {
// If decimal digits exist, keep them. Otherwise format them as usual.
if (integerAmount % 100 !== 0) {
return integerToCurrency(
integerAmount,
getNumberFormat({
...numberFormatConfig,
hideFraction: false,
}).formatter,
);
}
return integerToCurrency(integerAmount);
}
export function amountToCurrency(amount: Amount): CurrencyAmount {
return getNumberFormat().formatter.format(amount);
}

View File

@@ -0,0 +1,6 @@
---
category: Enhancements
authors: [csenel]
---
show full decimals while editing regardless of hide decimals setting