Browse Source

Introduce precision

pull/351/head
Thomas 4 years ago
parent
commit
39b27f54b4
  1. 3
      apps/client/src/app/components/position/position-detail-dialog/position-detail-dialog.html
  2. 10
      libs/ui/src/lib/value/value.component.stories.ts
  3. 8
      libs/ui/src/lib/value/value.component.ts

3
apps/client/src/app/components/position/position-detail-dialog/position-detail-dialog.html

@ -80,7 +80,8 @@
<gf-value
label="Quantity"
size="medium"
[isCurrency]="true"
[locale]="data.locale"
[precision]="2"
[value]="quantity"
></gf-value>
</div>

10
libs/ui/src/lib/value/value.component.stories.ts

@ -38,8 +38,14 @@ Integer.args = {
export const Label = Template.bind({});
Label.args = {
isInteger: true,
label: 'Label',
locale: 'en-US',
value: 7
value: 7.25
};
export const Precision = Template.bind({});
Precision.args = {
locale: 'en-US',
precision: 3,
value: 7.2534802394809285309
};

8
libs/ui/src/lib/value/value.component.ts

@ -23,6 +23,7 @@ export class ValueComponent implements OnChanges {
@Input() label = '';
@Input() locale = '';
@Input() position = '';
@Input() precision = 0;
@Input() size = '';
@Input() value: number | string = '';
@ -89,6 +90,13 @@ export class ValueComponent implements OnChanges {
minimumFractionDigits: 0
});
} catch {}
} else if (this.precision) {
this.formattedValue = this.value?.toLocaleString(this.locale, {
maximumFractionDigits: this.precision,
minimumFractionDigits: this.precision
});
} else {
this.formattedValue = this.value.toString();
}
} else {
try {

Loading…
Cancel
Save