本文整理汇总了TypeScript中@angular/common.DecimalPipe.transform方法的典型用法代码示例。如果您正苦于以下问题:TypeScript DecimalPipe.transform方法的具体用法?TypeScript DecimalPipe.transform怎么用?TypeScript DecimalPipe.transform使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@angular/common.DecimalPipe
的用法示例。
在下文中一共展示了DecimalPipe.transform方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: transform
transform(value: number, ...args: any[]): any {
let assetInfo = args.find(a => a instanceof Assets || a instanceof Object) as Assets;
let currency = args.find(a => typeof a === "string") as string;
let showCurrency = args.find(a => typeof a === "boolean");
if (showCurrency === undefined) {
showCurrency = true;
}
if (assetInfo && currency) {
let asset = assetInfo[currency] ? assetInfo[currency] :
(assetInfo['X' + currency] ? assetInfo['X' + currency] : null);
//(assetInfo['Z' + currency] ? assetInfo['Z' + currency] : null));
if (!asset && currency.startsWith('Z') && currency !== 'ZBT') {
return this.currencyPipe.transform(value, currency.substring(1, currency.length), true);
}
else if (!asset) {
return this.decimalPipe.transform(value, '1.5-5');
}
if (asset.assetClass === 'currency' && currency.startsWith('Z') && currency !== 'ZBT') {
return this.currencyPipe.transform(value, currency.substring(1, currency.length), true);
}
let displayDecimals = asset.displayDecimals.toString();
return this.decimalPipe.transform(value, '1.' + displayDecimals + '-' + displayDecimals);
} else if (currency) {
return this.currencyPipe.transform(value, currency.startsWith('Z') ? currency.substring(1, currency.length) : currency, true);
}
return this.decimalPipe.transform(value, '1.2-2');
}
示例2: formatFiatAmount
formatFiatAmount(amount: number) {
let value: any;
let sep: any;
let group: any;
let intValue: any;
let floatValue: any;
let finalValue: any;
value = this.decimalPipe.transform(amount);
if (!value) return 0;
sep = value.indexOf(this.formats.DECIMAL_SEP);
group = value.indexOf(this.formats.GROUP_SEP);
if (amount >= 0) {
if (group > 0) {
if (sep < 0) {
return value;
}
intValue = value.substring(0, sep);
floatValue = parseFloat(value.substring(sep));
floatValue = floatValue.toFixed(2);
floatValue = floatValue.toString().substring(1);
finalValue = intValue + floatValue;
return finalValue;
} else {
value = parseFloat(value);
return value.toFixed(2);
}
}
return 0;
}
示例3: transform
transform(amount: number, coin: string) {
return (
this.decimalPipe.transform(amount / 1e8, '1.2-6') +
' ' +
coin.toUpperCase()
);
}
示例4: transform
/**
* แปลง format ตัวเลข
* @param value ตัวเลข
* @param digits จำนวนตำแหน่งทศนิยม
* @param zeroSymbol สัญลักษณ์แทน 0
*/
transform(value: string | number, digits?: string, zeroSymbol?: string): string {
let number: number;
if (typeof value == 'undefined' || value == 'undefined')
number = 0
if (typeof value == 'string') {
number = Number(value);
if (value == 'NaN')
number = 0;
else if (isNaN(number))
return value;
}
else
number = value;
if (isNaN(number))
number = 0;
if (number != 0)
return this.decimalPipe.transform(number, digits);
else {
if (typeof zeroSymbol != 'undefined')
return zeroSymbol;
else
return '0';
}
}
示例5: it
it('should return correct value for numbers', () => {
expect(pipe.transform(12345)).toEqual('12,345');
expect(pipe.transform(123, '.2')).toEqual('123.00');
expect(pipe.transform(1, '3.')).toEqual('001');
expect(pipe.transform(1.1, '3.4-5')).toEqual('001.1000');
expect(pipe.transform(1.123456, '3.4-5')).toEqual('001.12346');
expect(pipe.transform(1.1234)).toEqual('1.123');
expect(pipe.transform(1.123456, '.2')).toEqual('1.123');
expect(pipe.transform(1.123456, '.4')).toEqual('1.1235');
});
示例6: transform
public transform(value: number, precision?: number): string {
if (!precision) {
precision = this.precision;
}
/**
* Min 1 place before the comma and exactly precision places after.
*/
const digitsInfo = `1.${precision}-${precision}`;
return this.decimalPipe.transform(value, digitsInfo);
}
示例7: it
it('should support strings', () => {
expect(pipe.transform('12345')).toEqual('12,345');
expect(pipe.transform('123', '.2')).toEqual('123.00');
expect(pipe.transform('1', '3.')).toEqual('001');
expect(pipe.transform('1.1', '3.4-5')).toEqual('001.1000');
expect(pipe.transform('1.123456', '3.4-5')).toEqual('001.12346');
expect(pipe.transform('1.1234')).toEqual('1.123');
});
示例8: transform
transform(amount: number, currencyCode: string, customPrecision?: number) {
const precision =
customPrecision || customPrecision === 0
? customPrecision
: this.getPrecision(currencyCode);
const numericValue = this.decimalPipe.transform(
amount,
this.getPrecisionString(precision)
);
const finalValue =
currencyCode.toUpperCase() === 'USD'
? `$${numericValue}`
: `${numericValue} ${currencyCode}`;
return finalValue;
}
示例9: transform
transform(
amount: number,
currencyCode: string,
customPrecision?: number | 'minimal'
) {
const precision =
customPrecision === 'minimal'
? getMinimalPrecision(amount, currencyCode)
: typeof customPrecision === 'number'
? customPrecision
: getPrecision(currencyCode);
const numericValue = this.decimalPipe.transform(
amount,
getPrecisionString(precision)
);
const finalValue =
currencyCode.toUpperCase() === 'USD'
? `$${numericValue}`
: `${numericValue} ${currencyCode}`;
return finalValue;
}
示例10: transform
public transform(input: number): string {
let decimalPlaces = 0,
dividend = 1,
formattedSize: string,
roundedSize: number,
template: string;
/* tslint:disable */
if (input === null || input === undefined) {
return '';
}
/* tslint:enable */
if (Math.abs(input) === 1) {
template = SkyResources.getString('file_size_b_singular');
} else if (input < 1000) {
template = SkyResources.getString('file_size_b_plural');
} else if (input < 1e6) {
template = SkyResources.getString('file_size_kb');
dividend = 1000;
} else if (input < 1e9) {
template = SkyResources.getString('file_size_mb');
dividend = 1e6;
decimalPlaces = 1;
} else {
template = SkyResources.getString('file_size_gb');
dividend = 1e9;
decimalPlaces = 1;
}
roundedSize =
Math.floor(input / (dividend / Math.pow(10, decimalPlaces))) / Math.pow(10, decimalPlaces);
formattedSize = this.decimalPipe.transform(roundedSize, '.0-3');
return SkyFormat.formatText(template, formattedSize);
}