<p>
My Salary : {{Salary | salary : "." : "US"}}
</p>
<p>
My Salary : {{Salary | salary : "," : "IN"}}
</p>
<p>
My Salary : {{Salary | salary }}
</p>
import { Component } from '@angular/core';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ]
})
export class AppComponent {
name = 'Angular';
Salary : String = '50000';
}
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'salary'
})
export class SalaryPipe implements PipeTransform {
transform(value: any, arg1?: string, arg2?: string): string {
var separator = ",";
var symbol = "₹";
if (arg1 != undefined) {
separator = arg1[0];
}
if (arg2 != undefined) {
switch (arg2) {
case "INR":
symbol = "₹";
break;
case "US":
symbol = "$";
break;
}
}
var formatedValue = "";
if (value.length > 3) {
formatedValue = separator + value.slice(length - 3);
value = value.slice(0, length - 3);
}
while (value.length > 2) {
formatedValue = separator + value.slice(value.length - 2) + formatedValue;
value = value.slice(0, value.length - 2);
}
formatedValue = value + formatedValue;
return symbol + formatedValue;
}
}