I have the following code to display in Indian numbering system.
var x=125465778; var res= x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
Am getting this output :125,465,778
.
I need output like this: 12,54,65,778
.
Please help me to sort out this problem .
JavaScript numbers can be formatted in different ways like commas, currency, etc. You can use the toFixed() method to format the number with decimal points, and the toLocaleString() method to format the number with commas and Intl. NumberFormat() method to format the number with currency.
Regular numbers in JavaScript are stored in 64-bit format IEEE-754, also known as “double precision floating point numbers”.
i'm late but i guess this will help :)
you can use Number.prototype.toLocaleString()
Syntax
numObj.toLocaleString([locales [, options]])
var number = 123456.789; // India uses thousands/lakh/crore separators document.getElementById('result').innerHTML = number.toLocaleString('en-IN'); // → 1,23,456.789 document.getElementById('result1').innerHTML = number.toLocaleString('en-IN', { maximumFractionDigits: 2, style: 'currency', currency: 'INR' }); // → ₹1,23,456.79
<div id="result"></div> <div id="result1"></div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With