0

I want an angular currency pipe to transcribe a number into czk currency in this way:

  • 1000 => 1 000 Kč
  • 3141592653589 => 3 141 592 653 589 Kč
  • 4 => 4 Kč

The pipe should also ensure, that the spaces between digits will never cause a line break between the digits for example by inserting a non-breaking space. I have guaranteed that there are no decimals.

How can I do that?

panSteven4
  • 21
  • 3
  • Check out transloco, that should provide what you need: https://ngneat.github.io/transloco/docs/plugins/locale#currency-pipe – Tino Aug 15 '23 at 15:59
  • Have you looked at this? https://angular.io/guide/pipes – khollenbeck Aug 15 '23 at 16:53
  • You probably need to give the implementation a try on your own first and share what issues you run into, if any, before asking on StackOverflow. – Jake Smith Aug 15 '23 at 16:55

1 Answers1

0

Make sure to import correct files.

TS file:

import { Component, LOCALE_ID } from '@angular/core';
import { registerLocaleData } from '@angular/common';
import localeCs from '@angular/common/locales/cs'; // Import the Czech locale

@Component({
  selector: 'app-currency-example',
  templateUrl: './currency-example.component.html',
  providers: [
    { provide: LOCALE_ID, useValue: 'cs-CZ' } // Set the Czech locale
  ]
})
export class CurrencyExampleComponent {
  amount: number = 12345.67;
  
  constructor() {
    registerLocaleData(localeCs); // Register the Czech locale data
  }
}

HTML:

<div>
  <p>Formatted CZK: {{ amount | currency: 'CZK':'symbol':'1.0-0' }}</p>
</div>
panSteven4
  • 21
  • 3