What are the parameters for the number Pipe - Angular 2

rushtoni88 picture rushtoni88 · Jul 20, 2016 · Viewed 116.3k times · Source

I have used the number pipe below to limit numbers to two decimal places.

{{ exampleNumber | number : '1.2-2' }}

I was wondering what the logic behind '1.2-2' was? I have played around with these trying to achieve a pipe which filters to zero decimal places but to no avail.

Answer

rinukkusu picture rinukkusu · Jul 20, 2016

The parameter has this syntax:

{minIntegerDigits}.{minFractionDigits}-{maxFractionDigits}

So your example of '1.2-2' means:

  • A minimum of 1 digit will be shown before decimal point
  • It will show at least 2 digits after decimal point
  • But not more than 2 digits