Created
July 14, 2017 05:01
-
-
Save neilbo/a8a7370836881b88354b79ad991436b2 to your computer and use it in GitHub Desktop.
Typescript Angular 2 Pipe for Custom Currency
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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