Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to transform dot to comma in an amount table?

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

>Solution :

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" class="text-end">{{ line.QUANTITY | number:'1.2-2':'fr-FR' }}</td>
   ...
</tr>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading