Check out the code snippet here: https://stackblitz.com/edit/angular-w5ecbw?file=src/app/app.component.ts
item.component.ts
ngOnInit() {
const data = ['.23.2 ms','.23.001 ms', '.23.81 ms', '192,101.02 ms', '1291,291.02 ms'];
for (let x = 0; x <= data.length; x++) {
console.log(this.formatData(data[x].replace(/ .+/, '')))
}
}
formatData(num: any) {
const [num1, num2] = String(num).split('.');
if (!num2) {
return num1;
} else {
return `${num1}.${num2}`;
}
}
The expected output should be:
.23.2
.23.001
.23.81
192101.02
1291291.02
I am looking to remove the comma in the output.