Home > Back-end >  Space in number format in Angular
Space in number format in Angular

Time:05-19

The value of a number is not displayed as I want.

For example, the number value is displayed like this currently 380000.00 and I want to display 380 000.00

How to create this space?

pipe

export class NumNoCommaPipe implements PipeTransform {

  isNotComma(charecter: string): boolean {
    return charecter !== ','
  }

  transform(value: string | null): string {
    return [...value!].filter(this.isNotComma).join("");
  }

}

CodePudding user response:

You should try to use an angular expression

const spaces = price => String(price)
  .replace(
    /(?!^)(?=(?:\d{3}) $)/g,
    ' '
  );

for (let i = 1; i < 1e10; i *= 10) {
  console.log(spaces(i));
}
  • Related