vuejs filter 2 decimal places

vuejs filter 2 decimal places

Today, We want to share with you vuejs filter 2 decimal places.In this post we will show you VueJS – Currency filter with rounding decimal places example, hear for Vuejs how to display number always with 2 decimal places in input tag we will give you demo and example for implement.In this post, we will learn about vuejs Rounding numbers to 2 digits after comma with an example.

vuejs filter 2 decimal places

There are the Following The simple About vuejs filter 2 decimal places Full Information With Example and source code.

As I will cover this Post with live Working example to develop Vuejs Formatting numbers with commas, so the vue js currency filter, vuejs format money for this example is following below.

Vuejs Filter Currency Round to 2 decimal places

index.html

<!DOCTYPE html>
<html>
<head>
  <title>www.pakainfo.com - VueJS - Currency filter with rounding decimal places example</title>
  <script src="https://unpkg.com/[email protected]/dist/vue.js"></script>
</head>
<body>
    <div id="root">
        Enter Your Price:
        <my-currency-filter-input v-model="productPrice"></my-currency-filter-input>
        <p>Price (in parent component): {{ productPrice }}</p>
    </div>
</body>
<script>
  Vue.component('my-currency-filter-input', {
      props: ["value"],
      template: `
          <div>
              <input type="text" Placeholder="Enetr Amount" v-model="previewPrrice" @blur="productInpData = false" @focus="productInpData = true"/>
          </div>`,
      data: function() {
          return {
              productInpData: false
          }
      },
      computed: {
          previewPrrice: {
              get: function() {
                  if (this.productInpData) {
                      return this.value.toString()
                  } else {
                      
                      return "$ " + this.value.toFixed(2).replace(/(\d)(?=(\d{3})+(?:\.\d+)?$)/g, "$1,")
                  }
              },
              set: function(liveProductValue) {
                  let liveVal = parseFloat(liveProductValue.replace(/[^\d\.]/g, ""))
                  if (isNaN(liveVal)) {
                      liveVal = 0
                  }
                  this.$emit('input', liveVal)
              }
          }
      }
  });
  new Vue({
      el: '#root',
      data: function() {
          return {
              productPrice: 526
          }
      }
  });
</script>
</html>

Web Programming Tutorials Example with Demo

Read :

Read Also:  Redirecting a Web Folder Directory to another Directory in htaccess

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about vuejs filter 2 decimal places.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

About Pakainfo

I am Jaydeep Gondaliya, a software engineer, the founder and the person running Pakainfo. I'm a full-stack developer, entrepreneur and owner of Pakainfo.com. I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by Pakainfo →

Leave a Reply

Your email address will not be published. Required fields are marked *