mirror of https://github.com/Squidex/squidex.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
956 B
35 lines
956 B
/*
|
|
* Squidex Headless CMS
|
|
*
|
|
* @license
|
|
* Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved.
|
|
*/
|
|
|
|
import { Pipe, PipeTransform } from '@angular/core';
|
|
import { CurrencyConfig, DecimalSeparatorConfig } from '@app/framework/internal';
|
|
|
|
@Pipe({
|
|
name: 'sqxMoney',
|
|
pure: true,
|
|
})
|
|
export class MoneyPipe implements PipeTransform {
|
|
constructor(
|
|
private readonly currency: CurrencyConfig,
|
|
private readonly separator: DecimalSeparatorConfig,
|
|
) {
|
|
}
|
|
|
|
public transform(value: number): any {
|
|
const money = value.toFixed(2).toString();
|
|
|
|
let result = `${money.substr(0, money.length - 3) + this.separator.value}<span class="decimal">${money.substr(money.length - 2, 2)}</span>`;
|
|
|
|
if (this.currency.showAfter) {
|
|
result = `${result} ${this.currency.symbol}`;
|
|
} else {
|
|
result = `${this.currency.symbol} ${result}`;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
}
|
|
|