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

Space in number format in Angular

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?

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

pipe

export class NumNoCommaPipe implements PipeTransform {

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

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

}

>Solution :

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));
}
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