Either by using javascript as following:
function numberWithSpaces(x) {
var parts = x.toString().split(".");
parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, " ");
return parts.join(".");
}
var num = numberWithSpaces(123456789);
console.log(num);
This will output 123 456 789
Edit:
Typescript:
function numberWithSpaces(x) {
let parts = x.toString().split('.');
parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ' ');
return parts.join('.');
}
let num = this.numberWithSpaces(123456789);
console.log(num);
add into your typescript file (.ts) which are related to your html which contain your <h2>item.price</h2>
replace num
with your item.price
value.
Or using pipe.
You could see example on Stackblitz
Just simply call by: element.price = format.formatCurrency(element.price);
Once you've define the helper. For your usage you could define by:
<h2 *ngFor="let item of item">{{ item.price }}</h2>