Convert Numbers to Indian Currency using JavaScript



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
Updated on: 2020-11-20T10:03:50+05:30

3K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements