UNPKG

inr-converter

Version:

inr-converter converts to indian rupees format when provide a string.

11 lines (9 loc) 338 B
const toRupees = (str) => { str = str.toString(); let lastThree = str.substring(str.length - 3); let otherNumbers = str.substring(0, str.length - 3); if (otherNumbers !== '') lastThree = ',' + lastThree; return otherNumbers.replace(/\B(?=(\d{2})+(?!\d))/g, ",") + lastThree; }; module.exports = { toRupees };