Vue.js round to two decimal places


We can use toFixed() method to round decimal numbers to two places. Here in this tutorial, we are going to explain how you can use this method to format a decimal number to two decimal places. You can also use our online editor to edit and run the code online.


Vue.js round to two decimal places – VueJs JavaScript Example

You can format decimal number to two decimal places simply as below-

Example:

<div id="app">	
	<p>Decimal Number = {{myNumber}}</p>
	<p>Result = {{formattedNumber}}</p>
	<button @click="myFunction()">Click Me</button>
</div>
<script>
 new Vue({
el: '#app',
  
  data: { 
	  myNumber:10.9865,
	  formattedNumber:'',
  },
  
   methods:{
    myFunction: function () {		
		this.formattedNumber = this.myNumber.toFixed(2);
    }
   }

});
</script>    

Try it »

Output of above example-

Vue.js round to two decimal places

Advertisements

Add Comment

📖 Read More