Skip to content

Instantly share code, notes, and snippets.

@neilbo
Created November 1, 2018 01:38
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/79fe3dfac2340b2f51ac6a419432a1aa to your computer and use it in GitHub Desktop.
Save neilbo/79fe3dfac2340b2f51ac6a419432a1aa to your computer and use it in GitHub Desktop.
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'thousandsComma',
})
export class ThousandsCommaPipe implements PipeTransform {
/**
* Takes a value and makes it '1000' or 1000 to '1,000'.
*/
transform(value: any) {
return value.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment