'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?
pipe
export class NumNoCommaPipe implements PipeTransform {
isNotComma(charecter: string): boolean {
return charecter !== ','
}
transform(value: string | null): string {
return [...value!].filter(this.isNotComma).join("");
}
}
Solution 1:[1]
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));
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Adriaan |
