Vue Js Convert Number To Lakh Or Crore: To convert numbers to lakh or crore in Vue.js, you can create a custom filter or method. First, divide the number by 1 lakh (100,000) or 1 crore (10,000,000) and format the result accordingly. For instance, if the number is 1,50,000, divide it by 100,000 to get 1.5. Then, use Vue.js’s filter or method to display it as “1.5 Lakh.” Similarly, for crores, divide by 10,000,000 and format it
How can I convert a number into the Indian numbering system format (Lakh or Crore) using Vuejs?
This Vue.js code snippet demonstrates how to convert numbers into a more readable format, either in Lakh or Crore, based on their magnitude. It defines a Vue application with a method called formatNumber
. When you input a number, it checks if it’s greater than or equal to 10 million (1 Crore) and formats it as Crore, or if it’s greater than or equal to 100,000 (1 Lakh) and formats it as Lakh, displaying up to two decimal places. Otherwise, it returns the number as is. This allows for better representation of large numbers in a user-friendly way on a web page.
Vue Js Convert Number To Lakh Or Crore Example
<div id="app">
<h3>Vue Js Convert Number to Lakh or Crore</h3>
<p>{{formatNumber(150000)}}</p>
<p>{{ formatNumber(12345678) }}</p>
<p>{{ formatNumber(123456789) }}</p>
<p>{{ formatNumber(12345) }}</p>
</div>
<script type="module">
const app = Vue.createApp({
methods: {
formatNumber: function (number) {
if (number >= 10000000) {
return (number / 10000000).toFixed(2) + ' Cr';
} else if (number >= 100000) {
return (number / 100000).toFixed(2) + ' Lakh';
}
return number.toString();
}
}
});
app.mount("#app");
</script>