Feature/improve numerical precision in holding detail dialog (#3584)

* Improve numerical precision in holding detail dialog

* Update changelog
This commit is contained in:
Thomas Kaul
2024-07-20 11:17:36 +02:00
committed by GitHub
parent 48eee5f865
commit ba78c2783d
8 changed files with 97 additions and 44 deletions

View File

@@ -29,7 +29,7 @@ export class GfValueComponent implements OnChanges {
@Input() isPercent = false;
@Input() locale: string;
@Input() position = '';
@Input() precision: number | undefined;
@Input() precision: number;
@Input() size: 'large' | 'medium' | 'small' = 'small';
@Input() subLabel = '';
@Input() unit = '';
@@ -58,8 +58,8 @@ export class GfValueComponent implements OnChanges {
this.formattedValue = this.absoluteValue.toLocaleString(
this.locale,
{
maximumFractionDigits: 2,
minimumFractionDigits: 2
maximumFractionDigits: this.precision,
minimumFractionDigits: this.precision
}
);
} catch {}
@@ -68,8 +68,8 @@ export class GfValueComponent implements OnChanges {
this.formattedValue = (this.absoluteValue * 100).toLocaleString(
this.locale,
{
maximumFractionDigits: 2,
minimumFractionDigits: 2
maximumFractionDigits: this.precision,
minimumFractionDigits: this.precision
}
);
} catch {}
@@ -77,8 +77,8 @@ export class GfValueComponent implements OnChanges {
} else if (this.isCurrency) {
try {
this.formattedValue = this.value?.toLocaleString(this.locale, {
maximumFractionDigits: 2,
minimumFractionDigits: 2
maximumFractionDigits: this.precision,
minimumFractionDigits: this.precision
});
} catch {}
} else if (this.isPercent) {
@@ -86,18 +86,11 @@ export class GfValueComponent implements OnChanges {
this.formattedValue = (this.value * 100).toLocaleString(
this.locale,
{
maximumFractionDigits: 2,
minimumFractionDigits: 2
maximumFractionDigits: this.precision,
minimumFractionDigits: this.precision
}
);
} catch {}
} else if (this.precision || this.precision === 0) {
try {
this.formattedValue = this.value?.toLocaleString(this.locale, {
maximumFractionDigits: this.precision,
minimumFractionDigits: this.precision
});
} catch {}
} else {
this.formattedValue = this.value?.toLocaleString(this.locale);
}
@@ -136,6 +129,7 @@ export class GfValueComponent implements OnChanges {
this.isNumber = false;
this.isString = false;
this.locale = this.locale || getLocale();
this.precision = this.precision >= 0 ? this.precision : 2;
this.useAbsoluteValue = false;
}
}