5

I am using the vue-currency-filter

and it works great. But there are times when the value it filters is not a number in my application. When that occurs it just show $0. I want it to show the text value that is not a number. when I have 345.23 I get $345.23 when I have 'No limit' I get $0 and i really want 'No Limit'

I have tried to include a ternary in my view but it fails. And i think that is related to this. Which i get but how can i solve this with a method?

Here is my relevant view html:

<div>{{ ch.Limit | currency }}</div>

and i tried something like:

<div>{{ Number.isNaN(ch.Limit) ? ch.Limit : ch.Limit | currency }}</div>

which doesn't work. I also tried to create a method like this:

valueIsCurrency(k) {
  return Number.isNaN(k) ? k | currency : k;
},

coupled with:

<div>{{ valueIsCurrency(ch.Limit) }}</div>

but the currency filter is not respected in the method. I suppose it is only for use in the render html portion. How can i fix this?

1 Answer 1

14

template

<div v-if="isNumber(ch.Limit)">{{ ch.Limit | currency }}</div>
<div v-else>{{ ch.Limit }}</div>

code

methods: {
  isNumber(n) {
    return typeof n === 'number';
  }
}
Sign up to request clarification or add additional context in comments.

3 Comments

@DerekPollard he's corrected the answer. Please don't hold people hostage with your votes.
@AndreiGheorghiu the problem is it creates yet another reason for people to consider SO a hostile place. Threatening with votes is not productive or polite.
@DerekPollard then write the answer that IS correct and let it get upvoted. That's the whole point of multiple answers and voting. This isn't a forum. Please, be civil and simply mention mistakes and work them out with conversation, not threats.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.