From cbbe77fceeeba275b44194e004dcc748ff9f1baf Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Sat, 20 Jul 2024 10:28:54 +0200 Subject: [PATCH] Improve numerical precision in holding detail dialog --- .../holding-detail-dialog.component.ts | 18 ++++++++++++++---- .../portfolio-performance.component.ts | 4 +++- libs/ui/src/lib/value/value.component.ts | 3 +-- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/apps/client/src/app/components/holding-detail-dialog/holding-detail-dialog.component.ts b/apps/client/src/app/components/holding-detail-dialog/holding-detail-dialog.component.ts index bb123d7e3..3ed2f13a5 100644 --- a/apps/client/src/app/components/holding-detail-dialog/holding-detail-dialog.component.ts +++ b/apps/client/src/app/components/holding-detail-dialog/holding-detail-dialog.component.ts @@ -167,7 +167,10 @@ export class GfHoldingDetailDialogComponent implements OnDestroy, OnInit { this.dataSource = new MatTableDataSource(orders.reverse()); this.dividendInBaseCurrency = dividendInBaseCurrency; - if (this.dividendInBaseCurrency >= NUMERICAL_PRECISION_THRESHOLD) { + if ( + this.data.deviceType === 'mobile' && + this.dividendInBaseCurrency >= NUMERICAL_PRECISION_THRESHOLD + ) { this.dividendInBaseCurrencyPrecision = 0; } @@ -193,7 +196,10 @@ export class GfHoldingDetailDialogComponent implements OnDestroy, OnInit { this.investment = investment; - if (this.investment >= NUMERICAL_PRECISION_THRESHOLD) { + if ( + this.data.deviceType === 'mobile' && + this.investment >= NUMERICAL_PRECISION_THRESHOLD + ) { this.investmentPrecision = 0; } @@ -202,7 +208,10 @@ export class GfHoldingDetailDialogComponent implements OnDestroy, OnInit { this.minPrice = minPrice; this.netPerformance = netPerformance; - if (this.netPerformance >= NUMERICAL_PRECISION_THRESHOLD) { + if ( + this.data.deviceType === 'mobile' && + this.netPerformance >= NUMERICAL_PRECISION_THRESHOLD + ) { this.netPerformancePrecision = 0; } @@ -215,8 +224,9 @@ export class GfHoldingDetailDialogComponent implements OnDestroy, OnInit { netPerformanceWithCurrencyEffect; if ( + this.data.deviceType === 'mobile' && this.netPerformanceWithCurrencyEffect >= - NUMERICAL_PRECISION_THRESHOLD + NUMERICAL_PRECISION_THRESHOLD ) { this.netPerformanceWithCurrencyEffectPrecision = 0; } diff --git a/apps/client/src/app/components/portfolio-performance/portfolio-performance.component.ts b/apps/client/src/app/components/portfolio-performance/portfolio-performance.component.ts index 4d205b761..f4e49ccaa 100644 --- a/apps/client/src/app/components/portfolio-performance/portfolio-performance.component.ts +++ b/apps/client/src/app/components/portfolio-performance/portfolio-performance.component.ts @@ -1,3 +1,4 @@ +import { NUMERICAL_PRECISION_THRESHOLD } from '@ghostfolio/common/config'; import { getLocale, getNumberFormatDecimal, @@ -54,7 +55,8 @@ export class PortfolioPerformanceComponent implements OnChanges, OnInit { decimal: getNumberFormatDecimal(this.locale), decimalPlaces: this.deviceType === 'mobile' && - this.performance?.currentValueInBaseCurrency >= 100000 + this.performance?.currentValueInBaseCurrency >= + NUMERICAL_PRECISION_THRESHOLD ? 0 : 2, duration: 1, diff --git a/libs/ui/src/lib/value/value.component.ts b/libs/ui/src/lib/value/value.component.ts index 14a1f2903..e1697d482 100644 --- a/libs/ui/src/lib/value/value.component.ts +++ b/libs/ui/src/lib/value/value.component.ts @@ -129,8 +129,7 @@ export class GfValueComponent implements OnChanges { this.isNumber = false; this.isString = false; this.locale = this.locale || getLocale(); - this.precision = - this.precision || this.precision === 0 ? this.precision : 2; + this.precision = this.precision >= 0 ? this.precision : 2; this.useAbsoluteValue = false; } }