import { Pipe , PipeTransform } from '@angular/core' ; @ Pipe ( { name : 'sharedNumberWithSeparator' } ) export class NumberWithSeparatorPipe implements PipeTransform { param value param locale returns { any } transform ( value , locale ? ) { let negative = '' ; if ( typeof value === 'undefined' || value === null ) { return '' ; } if ( value < 0 ) { negative = '-' ; value *= - 1 ; } const meta = this . _getLocaleInfo ( locale ) ; const parts = ( '' + value ) . split ( '.' ) ; const wholePart = parts [ 0 ] ; const decimalPart = parts [ 1 ] ; if ( typeof decimalPart === 'undefined' ) { return ( negative + value . toString ( ) . replace ( /\B(?=(\d{3})+(?!\d))/g , meta . separator ) ) ; } else { return ( negative + wholePart . replace ( /\B(?=(\d{3})+(?!\d))/g , meta . separator ) + meta . decimal + decimalPart ) ; } } param locale returns { { separator : string , decimal : string } } private _getLocaleInfo ( locale ) { const knownValue = 1000.1 ; const localeValue = knownValue . toLocaleString ( locale ) ; return { decimal : localeValue . substr ( 5 , 1 ) , separator : localeValue . substr ( 1 , 1 ) } ; } }