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.

  PHP Mail Attachment - Php Send Email File-Images Attachments

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]2.1.5/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 :

  jquery Compress or resize Image File Size before Uploading PHP Code

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.

Leave a Reply

avatar
  Subscribe  
Notify of