user14744011
user14744011

Reputation:

Angular how to turn the decimal to (.)

how do i turn some of the decimal to period(.) or dot?

this is my html

<p class="pointer" >{{grade.odds ? redot(grade.odds) : '--'}} </p>

this is my .ts

 redot(n){
    n = n.replace('%', '');
    console.log('n', n)
    n = this.env.moneyFormat(n, 2);
    return n + '%';
  }

for example

student 1 grade result : 100.452343234 %

what i desired result

student 1 grade result : 100.45....... %

Upvotes: 1

Views: 68

Answers (1)

Just Shadow
Just Shadow

Reputation: 11871

Angular has a useful pipe called DecimalPipe that solves the problem, so, no need of creating a new function.

Just use:

<p class="pointer" >{{grade.odds | number:'3.1-2'}} </p>

or if you want it to always have 2 digits after dot, then use:

<p class="pointer" >{{grade.odds | number:'3.2-2'}} </p>

P.S.: The format '3.1-2' means the number will have 3 digits before the dots, and 1-2 digits after the dot.

Upvotes: 1

Related Questions