I would like to know how to add spaces to obtain a number =>1545852125458 => x xx xx xxx xxx xx.
Sorry for my English.
My html : {{ item.numberDir }}
You should create a pipe for your needs.
Here I can share my pipe, which groups given number by 3 digits
Example: 123456789 -> 123 456 789
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'formatNumber',
})
export class FormatNumberPipe implements PipeTransform {
transform(value: number | string, ...args: unknown[]): string {
let v = String(value);
v = v.replace(/[^\d.]/g, '');
v = v.replace(/\./g, ',');
let parts = v.split(',');
let result = parts[0].replace(/(?!^)(?=(?:\d{3})+$)/g, ' ');
if (parts[1]) {
const glueSymbol = args[0] ? args[0] : ',';
result += glueSymbol + parts[1];
}
return result;
}
}