Skip to content

Instantly share code, notes, and snippets.

@neilbo
Created July 14, 2017 05:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neilbo/a8a7370836881b88354b79ad991436b2 to your computer and use it in GitHub Desktop.
Save neilbo/a8a7370836881b88354b79ad991436b2 to your computer and use it in GitHub Desktop.
Typescript Angular 2 Pipe for Custom Currency
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'currencyCustom'
})
export class CurrencyCustom implements PipeTransform {
/**
* @param value
*/
transform(value: any) {
let formattedNumber = parseFloat(value).toFixed(2).replace(/(\d)(?=(\d{3})+(?:\.\d+)?$)/g, "$1,");
return '$' + formattedNumber;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment