You may be looking for DecimalPipe .
Formatting is passed as a parameter to this channel as follows:
number:'{minIntegerDigits}.{minFractionDigits}-{maxFractionDigits}'
Using this with your needs:
number:'1.2-2'
This will give you a string with a minimum digit to the decimal point and exactly 2 after the decimal point.
Example use from documents:
@Component({ selector: 'number-example', pipes: [DecimalPipe], template: `<div> <p>e (no formatting): {{e}}</p> <p>e (3.1-5): {{e | number:'3.1-5'}}</p> <p>pi (no formatting): {{pi}}</p> <p>pi (3.5-5): {{pi | number:'3.5-5'}}</p> </div>` }) export class NumberPipeExample { pi: number = 3.141; e: number = 2.718281828459045; }
rinukkusu
source share