Elvin Mammadov
Elvin Mammadov

Reputation: 27387

Difference between succession of parameters on filtering

I am absolutely new in angularjs framework, and learning filtering now. I write a simple filtering for currency.

My codes are as follow:

{{99.9 | currency | number:0 }}

But this doesn't work for me, and nothing appear in browser, then I changed my code as:

{{99.9| number:0  | currency }}

Now I get result but it isn't my expectation: $100.00.

because I know that number:0 must give me result as: $100.

I want to know what is a difference between succession of parameters on filtering?

Thanks for reply.

Upvotes: 0

Views: 66

Answers (2)

przno
przno

Reputation: 3504

Let's have a look at this plunkr. Hope that it will help you to understand

Upvotes: 1

dmahapatro
dmahapatro

Reputation: 50245

Filters are applied to an expression serially the way they are used and separated by pipe |.

{{ 99.9 | currency | number:0 }}

Above applies, currency filter on 99.9 and then applies number filter with a 0 precision. As currency filter modifies 99.9 to $99.90, number filter cannot understand that and would fail to apply the filter.

On the other hand,

{{ 99.9 | number:0 | currency }} --> $100.00

using above, number filter rounds number 99.9 to 100 and then the currency filter is applied to see $100.00 in the end.

What you ultimately need would be

{{ 99.9 | number:1 | currency }} --> $99.90

if you want to maintain the precision.

Read more about different types of in-bult filters.

Upvotes: 1

Related Questions