Converting numbers to Indian currency using JavaScript

JavascriptWeb DevelopmentFront End TechnologyObject Oriented Programming

Suppose we have any number and are required to write a JavaScript function that takes in a number and returns its Indian currency equivalent.

toCurrency(1000) --> ₹4,000.00
toCurrency(129943) --> ₹1,49,419.00
toCurrency(76768798) --> ₹9,23,41,894.00

Example

The code for this will be −

const num1 = 1000;
const num2 = 129943;
const num3 = 76768798;
const toIndianCurrency = (num) => {
   const curr = num.toLocaleString('en-IN', {
      style: 'currency',
      currency: 'INR'
   });
return curr;
};
console.log(toIndianCurrency(num1));
console.log(toIndianCurrency(num2));
console.log(toIndianCurrency(num3));

Output

And the output in the console will be −

₹1,000.00
₹1,29,943.00
₹7,67,68,798.00
raja
Published on 20-Nov-2020 14:33:40
Advertisements