Home > Mobile >  How to add two dashes in a number?
How to add two dashes in a number?

Time:01-26

In output, I would like to display a number with this type of format => 979-9638403-03.

Currently, the number is displayed like this => 979963840303.

portfolio.ts

export class Portfolio {
    ...
    DEPO: number;         /* DEPO */
    
    constructor() {
        ...
        this.DEPO = 0;   /* DEPO */
    }
}

online.component.html

{{ ((currentPortfolio$ | async)?.DEPO) }}

Do you know if it is possible to add dashes? This is an aesthetic improvement.

I retrieve the value from a webservice for information.

I don't know if it's possible or not to do this on Angular?

CodePudding user response:

Check Angular's Slice Pipe :

If you convert the number to string you can do something like:

{{ '979963840303' | slice:0:3 }}-{{ '979963840303' | slice:3:-2 }}-{{ '979963840303' | slice:-2 }}

And that will output:

979-9638403-03

  • Related