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 <gf-value
label="Quantity" label="Quantity"
size="medium" size="medium"
[isCurrency]="true" [locale]="data.locale"
[precision]="2"
[value]="quantity" [value]="quantity"
></gf-value> ></gf-value>
</div> </div>

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

@ -38,8 +38,14 @@ Integer.args = {
export const Label = Template.bind({}); export const Label = Template.bind({});
Label.args = { Label.args = {
isInteger: true,
label: 'Label', label: 'Label',
locale: 'en-US', 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() label = '';
@Input() locale = ''; @Input() locale = '';
@Input() position = ''; @Input() position = '';
@Input() precision = 0;
@Input() size = ''; @Input() size = '';
@Input() value: number | string = ''; @Input() value: number | string = '';
@ -89,6 +90,13 @@ export class ValueComponent implements OnChanges {
minimumFractionDigits: 0 minimumFractionDigits: 0
}); });
} catch {} } 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 { } else {
try { try {

Loading…
Cancel
Save