Skip to content

Commit

Permalink
added method getGrouping
Browse files Browse the repository at this point in the history
  • Loading branch information
lkramarov committed Aug 19, 2019
1 parent c603832 commit 9414145
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions packages/mosaic/core/formatters/number/formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ function parseDigitsInfo(digitsInfo: string): ParsedDigitsInfo {
@Injectable({ providedIn: 'root' })
@Pipe({name: 'mcNumber'})
export class McDecimalPipe implements PipeTransform {
protected minimumNumberForGrouping = 10000;
minimumNumberForGroupingForRuLocale = 10000;

constructor(@Optional() @Inject(MC_LOCALE_ID) private _locale: string) {}

Expand Down Expand Up @@ -124,19 +124,27 @@ export class McDecimalPipe implements PipeTransform {
try {
const num = strToNumber(value);

options.useGrouping = num >= this.minimumNumberForGrouping;
options.useGrouping = this.getGrouping(num, currentLocale);

return Intl.NumberFormat.call(this, currentLocale, options).format(num);
} catch (error) {
throw Error(`InvalidPipeArgument: McDecimalPipe for pipe '${JSON.stringify(error.message)}'`);
}
}

getGrouping(num: number, locale: string): boolean {
if (locale === 'ru') {
return num >= this.minimumNumberForGroupingForRuLocale;
}

return true;
}
}

@Injectable({ providedIn: 'root' })
@Pipe({name: 'mcTableNumber'})
export class McTableDecimalPipe extends McDecimalPipe {
protected minimumNumberForGrouping = 1000;
minimumNumberForGroupingForRuLocale = 1000;

constructor(@Optional() @Inject(MC_LOCALE_ID) locale: string) {
super(locale);
Expand Down

0 comments on commit 9414145

Please sign in to comment.