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.
Angular Decimal Pipe is one of the bulit in pipe in Angular used to format decimal numbers according to the given decimal digits info and locale information.
You can easily pass multiple arguments in pipe in angular 6, angular 7, angular 8, angular 9, angular 10, angular 11, angular 12, angular 13 and angular 14 application. In this example we will create 'descPipe' custom pipe and create dynamic description with multiple parameters.
These filters are known as "Pipes" in Angular 2. Pipes allow us to change the data inside the template. Normally, a pipe takes the data and transforms this input to the desired output. There are many built-in pipes in Angular 2.
In your component's template you can use multiple arguments by separating them with colons: {{ myData | myPipe: 'arg1':'arg2':'arg3'... }} Pipes take an array that contains all arguments, so you need to call them like this: new MyPipe().
The parameter has this syntax:
{minIntegerDigits}.{minFractionDigits}-{maxFractionDigits}
So your example of '1.2-2'
means:
Regarding your first question.The pipe works as follows:
numberValue | number: {minIntegerDigits}.{minFractionDigits}-{maxFractionDigits}
minFractionDigits: Minimum number of integer digits to show after the decimal point
maxFractionDigits: Maximum number of integer digits to show after the decimal point
2.Regarding your second question, Filter to zero decimal places as follows:
{{ numberValue | number: '1.0-0' }}
For further reading, checkout the following blog
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With