• Skip to main content
  • Skip to primary sidebar

Web Development Archive

  • Archive
You are here: Home / Other / Thousand Separator

Thousand Separator

With Comma

{{ number | number: '1.0-0' }}
420,000

With Space

420 000

Thousand Separator Pipe

import { Pipe, PipeTransform } from '@angular/core';

@Pipe({
  name: 'thousandSeparator',
  standalone: true,
})
export class ThousandSeparatorPipe implements PipeTransform {
  transform(value: number): string {
    return value.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ' ');
  }
}
{{ number | thousandSeparator }}

Ha az adat, ami backendről érkezik string

import { Pipe, PipeTransform } from '@angular/core';

@Pipe({
name: 'thousandSeparator',
standalone: true,
})
export class ThousandSeparatorPipe implements PipeTransform {
public transform(value: number | string): string {
if (typeof value === 'string') {
const parsedValue = parseFloat(value.replace(/,/g, ''));
if (isNaN(parsedValue)) {
return value;
}
value = parsedValue;
}

return value.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ' ');
}
}

Filed Under: Other

About Gabor Flamich

I'm a web developer and designer based in Budapest, Hungary. In recent years, I've documented hundreds of solutions I came across during development. This site is an archive for useful code snippets on WordPress, Genesis Framework and WooCommerce. If You have any questions related to WordPress development, get in touch!

Primary Sidebar

  • angular.io
© 2026 WP Flames - All Right Reserved