Corner 5+
Starting with Angular 5, the locale argument has been added to the decimal pipe, as you can see in the official documentation: https://angular.io/api/common/DecimalPipe . This means that you can select your language directly when calling the channel, for example:
{{p.total | number:'':'fr-FR'}}
Just keep in mind that the decimal separator will also change.
Corner 2+
or if you want to change ONLY the thousands separator ...
According to Angular's documentation for DecimalPipe: https://v2.angular.io/docs/ts/latest/api/common/index/DecimalPipe-pipe.html , there is no explicit argument that can be added to a channel call to exclusively change the characters used to formatting.
If you donโt want to change the locale or related defaults for your entire project, I think your best way is to write your own channel dedicated to your special occasion. Do not worry, pipes are very easy to write.
import { Pipe, PipeTransform } from '@angular/core'; @Pipe({ name: 'numberfr' }) export class FrenchDecimalPipe implements PipeTransform { transform(val: number): string { // Format the output to display any way you want here. // For instance: if (val !== undefined && val !== null) { return val.toLocaleString(/*arguments you need*/); } else { return ''; } } }
Remember to add it to NgModule to use it.
Adrien brunelat
source share