To format Indian Rupee format using Javascript, you can use the toLocaleString() method, which allows you to format a number according to the local conventions of a given locale. In order to format a number as Indian Rupee in JavaScript, you can use the Intl.NumberFormat object. This object allows you to configure the formatting options, such as the locale, style, currency, and minimum fraction digits. The locale is a code that represents the language and region, and it is set to ‘en-IN’ for Indian English. The style is set to ‘currency’ to indicate that the number should be formatted as a currency value. The currency is set to ‘INR’ for Indian Rupee. The minimum fraction digits specify the minimum number of digits to show after the decimal point. Once the formatting options are configured, you can use the format method to format the number and return the result.
Here is the Copy paste code you can copy paste to your project.
<script> function indiancurrency(amt) { var x=amt; x=x.toString(); var lastThree = x.substring(x.length-3); var otherNumbers = x.substring(0,x.length-3); if(otherNumbers != '') lastThree = ',' + lastThree; var res = otherNumbers.replace(/\B(?=(\d{2})+(?!\d))/g, ",") + lastThree; return res; } </script>
<script> alert(indiancurrency(5000)); </script>
To format a number as Indian Rupee in JavaScript, you can use the Intl.NumberFormat object. Here is an example:
let amount = 12345.67;
let formatter = new Intl.NumberFormat('en-IN', {
style: 'currency',
currency: 'INR',
minimumFractionDigits: 2
});
let result = formatter.format(amount);
console.log(result); // "₹12,345.67"
In this example, amount
is the number you want to format, and formatter
is an instance of the Intl.NumberFormat
object that is configured to format the number as Indian Rupee. The first argument passed to the constructor is the locale, which is set to ‘en-IN’ for Indian English. The second argument is an options object that specifies the formatting options, including the style, currency, and minimum fraction digits. The format
method is used to format the number and return the result.