Skip to content

Commit

Permalink
Merge pull request #3488 from ita-social-projects/bugfix/#7890-round-…
Browse files Browse the repository at this point in the history
…number

[Bugfix] #7890, #7907 round the number and add 2 digits after the point
  • Loading branch information
kryzanivska-nastya authored Dec 16, 2024
2 parents fe5ad1d + c2d7bd0 commit 85c7d4c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
15 changes: 10 additions & 5 deletions src/app/shared/localized-currency-pipe/localized-currency.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const LOCALIZED_CURRENCY = {
})
export class LocalizedCurrencyPipe implements PipeTransform, OnDestroy {
private lang: string;
private destroy$: Subject<any> = new Subject();
private destroy$: Subject<void> = new Subject();

constructor(translate: TranslateService, localStorageService: LocalStorageService) {
this.lang = localStorageService.getCurrentLanguage() || translate.defaultLang;
Expand All @@ -25,12 +25,17 @@ export class LocalizedCurrencyPipe implements PipeTransform, OnDestroy {
});
}

transform(value: any): any {
return `${value} ${LOCALIZED_CURRENCY[this.lang]}`;
transform(value: number | string | null, fixedDigits: boolean = false): string | null {
if (value == null || isNaN(Number(value))) {
return null;
}

const formattedValue = fixedDigits ? Number(value).toFixed(2) : Math.round(Number(value) * 100) / 100;
return `${formattedValue} ${LOCALIZED_CURRENCY[this.lang]}`;
}

ngOnDestroy() {
this.destroy$.next(true);
this.destroy$.unsubscribe();
this.destroy$.next();
this.destroy$.complete();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ <h5 *ngIf="!currentLocation" class="error-text">{{ 'order-details.title-without-
<li *ngFor="let bag of bags" class="main-list-item">
<span class="bag-name" [appLangValue]="{ ua: bag.name, en: bag.nameEng }"></span>
<span class="bag-name">{{ bag.capacity | volume }}</span>
<span class="bag-name">{{ bag.price | localizedCurrency }}</span>
<span class="bag-name">{{ bag.price | localizedCurrency: true }}</span>
<div class="bag-name form-group count">
<div class="quantity-input-wrapper">
<button (click)="changeQuantity(bag.id, -1)" type="button">
Expand All @@ -55,7 +55,7 @@ <h5 *ngIf="!currentLocation" class="error-text">{{ 'order-details.title-without-
</button>
</div>
</div>
<span class="bag-name label-total"> {{ getBagQuantity(bag.id) * bag.price | localizedCurrency }}</span>
<span class="bag-name label-total"> {{ getBagQuantity(bag.id) * bag.price | localizedCurrency: true }}</span>
</li>
</ul>
</div>
Expand All @@ -66,7 +66,7 @@ <h5 *ngIf="!currentLocation" class="error-text">{{ 'order-details.title-without-
<p class="total-content" [class.d-none]="orderSum === 0">
<span>{{ 'order-details.order-amount' | translate }}</span>
<span>
<strong>{{ orderSum | localizedCurrency }}</strong>
<strong>{{ orderSum | localizedCurrency: true }}</strong>
</span>
</p>
<p class="total-content" *ngIf="certificateUsed">
Expand All @@ -84,7 +84,7 @@ <h5 *ngIf="!currentLocation" class="error-text">{{ 'order-details.title-without-
<p class="total-content">
<span>{{ 'order-details.amount-due' | translate }} </span>
<span>
<strong>{{ finalSum | localizedCurrency }}</strong>
<strong>{{ finalSum | localizedCurrency: true }}</strong>
</span>
</p>
</div>
Expand Down

0 comments on commit 85c7d4c

Please sign in to comment.