How to transform dot to comma in an amount table?

Viewed 63

I have a little question, how to replace the "dot" with a "comma", in the quantity field?

enter image description here

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" class="text-end">{{ 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.

1 Answers

You are using the DecimalPipe which 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 case you don't even need a custom pipe, you can simply use the DecimalPipe directly:

<tr *ngFor="let line of osts">
   ...
   <td scope="row" class="text-end">{{ line.QUANTITY | number:'1.2-2':'fr-FR' }}</td>
   ...
</tr>
Related