0

I want to display the variable from the database and round it before. Can you help me about syntax for this.

<h2 class="txt-bold">Rating: {{roundHalf(ListOrg.rating)}}</h2>


computed: {
    roundHalf: function(num) {
      return Math.round(num * 2) / 2;
    }
  }
1
  • If you want to pass a parameter, then it becomes a method Commented Mar 27, 2019 at 2:37

2 Answers 2

1

If you want to use computed value :

<h2 class="txt-bold">Rating: {{roundHalf}}</h2>


computed: {
    roundHalf: function() {
      return Math.round(this.ListOrg.rating * 2) / 2;
    }
  }
Sign up to request clarification or add additional context in comments.

Comments

1

Better to use Vue filter :

Define a filter : (Global filter)

Vue.filter('roundHalf', function (value) {
    return Math.round(value * 2) / 2;
})

And use in vue file like :

<h2 class="txt-bold">Rating: {{ListOrg.rating | roundHalf}}</h2>

Defining a global filter will help you use it everywhere in the project. :)

Reference : Vue Filter

Comments

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.