Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 142159

How to remove the comma using the replace in angular

$
0
0

here's the code: 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}`;
    }
  }

expected output should be:

.23.2
.23.001
    .23.81
    192101.02
    1291291.02

What I want to do here is to remove the comma.


Viewing all articles
Browse latest Browse all 142159

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>