I have a little question, how to replace the "dot" with a "comma", in the quantity field?
Instead of getting 587.00
, I want to obtain 587,00
.
I have no idea how to convert this?
Here is my code for now:
HTML
<tr *ngFor="let line of osts">
...
<td scope="row" >{{ line.QUANTITY | variableFormatNum: "1.2-2" }}</td>
...
</tr>
variable-format-num.pipe.ts
import { DecimalPipe } from '@angular/common';
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({ name: 'variableFormatNum' })
export class VariableFormatNumPipe implements PipeTransform {
constructor(private decimalPipe: DecimalPipe) {
}
transform(input: number | string | null | undefined, digitsInfo?: string): string | null {
return this.decimalPipe.transform(input, digitsInfo);
}
}
Thank you in advance.
CodePudding user response:
You are using the DecimalPipe
whitch has a locale
parameter you can use to show a "comma".
Use for example French locale:
transform(input: number | string | null | undefined, digitsInfo?: string, locale: string = 'fr-FR'): string | null {
return this.decimalPipe.transform(input, digitsInfo, locale);
}
For more information see the docs.
In your can you dont even need a custom pipe, you can simple use the DecialPipe
directly:
<tr *ngFor="let line of osts">
...
<td scope="row" >{{ line.QUANTITY | number:'1.2-2':'fr-FR' }}</td>
...
</tr>