Remove the dash from a negative number

Viewed 562

When I display the negative number for example -0.24%... I would like to remove the dash please. I don't know how to change it ?

I don't need of the dash because I have a red arrow.

enter image description here

I don't know if the probleme is here to remove the dash?

<div class="" style="width: 20% !important;">
    <h5 style="text-align: right;">
      {{ n.variation | number:'1.2-2' | projectformatnum }}&nbsp;%
      <span *ngIf="n.variation < 0"
      style="
         background: url(/assets/images/project-online-sprites.png) 1px -834px no-repeat; 
         position: relative; 
         top: 3px;
         margin-left: 10px;">
    </span>
    </h5>
</div>
3 Answers

you can use Math.abs function for this.

Example

n.variation // -0.24

Math.abs(n.variation) // 0.24

You can create a custom pipe:

By angular-cli: ng g pipe abs

@Pipe({name: 'abs'})

export class abs implements PipeTransform {
  transform(num: number, args?: any): any {
    return Math.abs(num);
  }
}

you can change your template as:

{{ n.variation | number:'1.2-2' | projectformatnum | abs }}

You can use also conditional operator before pipe the number

{{ (n.variation<0?-n.variation:n.variation) | number:'1.2-2' | projectformatnum }}

Or in your pipe projectformatnum use some similar to return always a positive number formated (I don't know about your pipe)

Related