Reza
Reza

Reputation: 880

Showing price 2 decimal places with comma angular7 / ionic4

Hi from the api i return prices such as 1.00 or 2.00 but in the template i want to show this as €1,00 or €2,00. Im doing following:

<ion-icon name="pricetag" color="secondary"></ion-icon> Minimale Kbestelling <B>{{item.minimal_order | currency:'EUR'}}</B>

How can i replace the . for a comma? I know the thousand seperator uses a comma but i want to show only comma's how can i do this ?

i dont see a option to do this: https://angular.io/api/common/CurrencyPipe

Upvotes: 2

Views: 611

Answers (1)

Mike Hill
Mike Hill

Reputation: 3782

The Angular internationalization page (https://angular.io/guide/i18n) provides a wealth of information about localizing your app. If you want to use a comma radix instead of a decimal, you can choose an appropriate locale and then include it as a parameter for your currency pipe configuration.

The fourth parameter to the currency pipe is the locale to use for display, which determines whether a comma or a period is used as the radix symbol. For example, the fr locale might look like this:

https://codesandbox.io/s/k203o9nr07

import { Component } from "@angular/core";
import { registerLocaleData } from "@angular/common";
import localeFr from "@angular/common/locales/fr";

registerLocaleData(localeFr, "fr");

@Component({
  selector: "app-root",
  template: "<div>My number is {{this.value | currency:'EUR':'symbol':'':'fr'}}</div>"
})
export class AppComponent {
  value = 1234.5678;
}

Sources:

Upvotes: 2

Related Questions