diff --git a/src/app/dashboard/dashboard.html b/src/app/dashboard/dashboard.html index 26eb95a..5c92a3e 100644 --- a/src/app/dashboard/dashboard.html +++ b/src/app/dashboard/dashboard.html @@ -20,7 +20,7 @@
Current spending
-
{{expenseAmount | currencyFormat:org.precision}}
+
{{expenseAmount | currencyFormat:org.precision:org.currency}}
@@ -28,7 +28,7 @@ {{expense.fullName | accountName:2}}
- {{expense.nativeBalanceCost | currencyFormat:org.precision}} + {{expense.nativeBalanceCost | currencyFormat:org.precision:org.currency}}
@@ -62,7 +62,7 @@ {{recentTx.tx.description}}
- {{-recentTx.split.amount | currencyFormat:recentTx.account.precision}} + {{-recentTx.split.amount | currencyFormat:recentTx.account.precision:recentTx.account.currency}}
diff --git a/src/app/reports/balancesheet.html b/src/app/reports/balancesheet.html index 9d052b6..f0bd0c5 100644 --- a/src/app/reports/balancesheet.html +++ b/src/app/reports/balancesheet.html @@ -29,8 +29,8 @@

Assets

-

{{+assetAccount.totalNativeBalancePrice | currencyFormat:org.precision}}

-

{{+assetAccount.totalNativeBalanceCost | currencyFormat:org.precision}}

+

{{+assetAccount.totalNativeBalancePrice | currencyFormat:org.precision:org.currency}}

+

{{+assetAccount.totalNativeBalanceCost | currencyFormat:org.precision:org.currency}}

@@ -39,10 +39,10 @@ {{account.name | slice:0:30}}
- {{+account.totalNativeBalancePrice | currencyFormat:org.precision}} + {{+account.totalNativeBalancePrice | currencyFormat:org.precision:org.currency}}
- {{+account.totalNativeBalanceCost | currencyFormat:org.precision}} + {{+account.totalNativeBalanceCost | currencyFormat:org.precision:org.currency}}
@@ -55,8 +55,8 @@

Liabilities

-

{{-liabilityAccount.totalNativeBalancePrice | currencyFormat:org.precision}}

-

{{-liabilityAccount.totalNativeBalanceCost | currencyFormat:org.precision}}

+

{{-liabilityAccount.totalNativeBalancePrice | currencyFormat:org.precision:org.currency}}

+

{{-liabilityAccount.totalNativeBalanceCost | currencyFormat:org.precision:org.currency}}

@@ -65,10 +65,10 @@ {{account.name | slice:0:30}}
- {{-account.totalNativeBalancePrice | currencyFormat:org.precision}} + {{-account.totalNativeBalancePrice | currencyFormat:org.precision:org.currency}}
- {{-account.totalNativeBalanceCost | currencyFormat:org.precision}} + {{-account.totalNativeBalanceCost | currencyFormat:org.precision:org.currency}}
@@ -76,8 +76,8 @@

Equity

-

{{-equityAccount.totalNativeBalancePrice | currencyFormat:org.precision}}

-

{{-equityAccount.totalNativeBalanceCost | currencyFormat:org.precision}}

+

{{-equityAccount.totalNativeBalancePrice | currencyFormat:org.precision:org.currency}}

+

{{-equityAccount.totalNativeBalanceCost | currencyFormat:org.precision:org.currency}}

@@ -86,10 +86,10 @@ {{account.name | slice:0:30}}
- {{-account.totalNativeBalancePrice | currencyFormat:org.precision}} + {{-account.totalNativeBalancePrice | currencyFormat:org.precision:org.currency}}
- {{-account.totalNativeBalanceCost | currencyFormat:org.precision}} + {{-account.totalNativeBalanceCost | currencyFormat:org.precision:org.currency}}
diff --git a/src/app/reports/income.html b/src/app/reports/income.html index 198c887..7f83edb 100644 --- a/src/app/reports/income.html +++ b/src/app/reports/income.html @@ -24,7 +24,7 @@

Income

-

{{-incomeAccount.totalNativeBalanceCost | currencyFormat:org.precision}}

+

{{-incomeAccount.totalNativeBalanceCost | currencyFormat:org.precision:org.currency}}

@@ -33,7 +33,7 @@ {{account.name | slice:0:30}}
- {{-account.totalNativeBalanceCost | currencyFormat:org.precision}} + {{-account.totalNativeBalanceCost | currencyFormat:org.precision:org.currency}}
@@ -41,7 +41,7 @@

Expenses

-

{{expenseAccount.totalNativeBalanceCost | currencyFormat:org.precision}}

+

{{expenseAccount.totalNativeBalanceCost | currencyFormat:org.precision:org.currency}}

@@ -50,7 +50,7 @@ {{account.name | slice:0:30}}
- {{account.totalNativeBalanceCost | currencyFormat:org.precision}} + {{account.totalNativeBalanceCost | currencyFormat:org.precision:org.currency}}
@@ -58,7 +58,7 @@

Net Income

-

{{-incomeAccount.totalNativeBalanceCost - expenseAccount.totalNativeBalanceCost | currencyFormat:org.precision}}

+

{{-incomeAccount.totalNativeBalanceCost - expenseAccount.totalNativeBalanceCost | currencyFormat:org.precision:org.currency}}

diff --git a/src/app/shared/currency-format.pipe.ts b/src/app/shared/currency-format.pipe.ts index 345b379..edbd758 100644 --- a/src/app/shared/currency-format.pipe.ts +++ b/src/app/shared/currency-format.pipe.ts @@ -1,7 +1,16 @@ import { Pipe, PipeTransform } from '@angular/core'; import { DecimalPipe } from '@angular/common'; -@Pipe({name: 'currencyFormat'}) +// Format the currency according to the user's browser locale. +// +// Some currencies share the same symbol (e.g. $ is used for USD and CAN). +// Ideally, the user experience should not be confusing if different accounts +// have conflicting symbols. One solution might be to always show the ISO +// currency code for accounts with mixes currencies. Another solution would be +// to let the user configure how the currency is displayed on a per-currency +// or per-account basis. + +@Pipe({ name: 'currencyFormat' }) export class CurrencyFormatPipe implements PipeTransform { constructor(private decimalPipe: DecimalPipe) { } @@ -11,17 +20,12 @@ export class CurrencyFormatPipe implements PipeTransform { return ''; } - let prefix = amount < 0 ? '-' : ''; - - if(currency === 'USD') { - prefix += '$'; - } - - let minDigits = Math.min(2, precision); - - return prefix + - this.decimalPipe.transform( - Math.abs(amount) / Math.pow(10, precision), - '1.' + minDigits + '-' + precision); + // note: we can drop the cast to any if we change the ts target from es5 to es2020 or newer. + return Intl.NumberFormat(navigator.language, { + style: "currency", + currency, + minimumFractionDigits: precision, + signDisplay: "negative", + } as any).format(amount / Math.pow(10, precision)); } } \ No newline at end of file